use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.
the class TestCaseExporter method writeExecutionTimesForPathAndHttpMethod.
private void writeExecutionTimesForPathAndHttpMethod(String key, List<CatsTestCase> value) {
double average = value.stream().mapToLong(testCase -> testCase.getResponse().getResponseTimeInMs()).average().orElse(0);
List<CatsTestCase> sortedRuns = value.stream().sorted(Comparator.comparingLong(testCase -> testCase.getResponse().getResponseTimeInMs())).collect(Collectors.toList());
CatsTestCase bestCase = sortedRuns.get(0);
CatsTestCase worstCase = sortedRuns.get(sortedRuns.size() - 1);
List<String> executions = sortedRuns.stream().map(CatsTestCase::executionTimeString).collect(Collectors.toList());
TimeExecutionDetails timeExecutionDetails = TimeExecutionDetails.builder().average(average).path(key).bestCase(bestCase.executionTimeString()).worstCase(worstCase.executionTimeString()).executions(executions).build();
LOGGER.info("Details for path {} ", ansi().fg(Ansi.Color.GREEN).a(timeExecutionDetails.getPath()).reset());
LOGGER.note(ansi().fgYellow().a("Average response time: {}ms").reset().toString(), ansi().bold().a(NumberFormat.getInstance().format(timeExecutionDetails.getAverage())));
LOGGER.note(ansi().fgRed().a("Worst case response time: {}").reset().toString(), ansi().bold().a(timeExecutionDetails.getWorstCase()));
LOGGER.note(ansi().fgGreen().a("Best case response time: {}").reset().toString(), ansi().bold().a(timeExecutionDetails.getBestCase()));
if (reportingArguments.isPrintDetailedExecutionStatistics()) {
LOGGER.note("{} executed tests (sorted by response time): {}", timeExecutionDetails.getExecutions().size(), timeExecutionDetails.getExecutions());
LOGGER.info(" ");
}
}
use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.
the class TestCaseListenerTest method givenAnUndocumentedResponseThatIsNotExpected_whenReportingTheResult_thenTheResultIsCorrectlyReported.
@Test
void givenAnUndocumentedResponseThatIsNotExpected_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("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();
CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
Assertions.assertThat(testCase.getResultDetails()).startsWith("Unexpected behaviour");
}
use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.
the class TestCaseListenerTest method shouldStorePostRequestAndRemoveAfterDelete.
@Test
void shouldStorePostRequestAndRemoveAfterDelete() {
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()));
Mockito.when(data.getMethod()).thenReturn(HttpMethod.POST);
Mockito.when(data.getPath()).thenReturn("/test");
MDC.put(TestCaseListener.ID, "Test 1");
testCaseListener.testCaseMap.put("Test 1", new CatsTestCase());
testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX);
Assertions.assertThat(catsGlobalContext.getPostSuccessfulResponses()).hasSize(1).containsKey("/test");
Assertions.assertThat(catsGlobalContext.getPostSuccessfulResponses().get("/test")).isNotEmpty();
Mockito.when(data.getMethod()).thenReturn(HttpMethod.DELETE);
Mockito.when(data.getPath()).thenReturn("/test/{testId}");
testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX);
Assertions.assertThat(catsGlobalContext.getPostSuccessfulResponses()).hasSize(1).containsKey("/test");
Assertions.assertThat(catsGlobalContext.getPostSuccessfulResponses().get("/test")).isEmpty();
MDC.remove(TestCaseListener.ID);
testCaseListener.testCaseMap.clear();
}
use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.
the class TestCaseListenerTest method givenATestCase_whenExecutingItAndAWarnHappens_thenTheWarnIsCorrectlyReportedWithinTheTestCase.
@Test
void givenATestCase_whenExecutingItAndAWarnHappens_thenTheWarnIsCorrectlyReportedWithinTheTestCase() {
testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportWarn(logger, "Warn {} happened", "1"));
Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseWarns();
Mockito.verify(executionStatisticsListener, Mockito.never()).increaseErrors();
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.WARN.toString().toLowerCase());
Assertions.assertThat(testCase.getResultDetails()).isEqualTo("Warn 1 happened");
}
Aggregations