use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class TestCaseParserTests method testCreateTestCasesWithStatusFilter.
@Test
void testCreateTestCasesWithStatusFilter() throws URISyntaxException, IOException {
var objectMapper = configureObjectMapper();
Path sourceDirectory = Paths.get(getClass().getResource(RESOURCE_PATH).toURI());
when(zephyrExporterProperties.getSourceDirectory()).thenReturn(sourceDirectory);
when(zephyrExporterProperties.getStatusesOfTestCasesToAddToExecution()).thenReturn(List.of(TestCaseStatus.PASSED));
List<TestCase> testCases = testCaseParser.createTestCases(objectMapper);
assertEquals(testCases.size(), 1);
List<LoggingEvent> events = testLogger.getLoggingEvents();
assertThat(events.get(0).getMessage(), is(JSON_FILES_STRING));
assertThat(events.get(0).getLevel(), is(Level.INFO));
assertThat(events.get(1).getMessage(), is(TEST_CASES_STRING));
assertThat(events.get(1).getLevel(), is(Level.INFO));
assertThat(events.get(2), is(info(FOR_EXPORTING_STRING, testCases)));
assertThat(events.size(), equalTo(3));
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class StatisticsStoryReporterTests method shouldLogMessageInCaseOfIOException.
@Test
void shouldLogMessageInCaseOfIOException(@TempDir File tempDir) {
try (MockedStatic<Files> files = mockStatic(Files.class)) {
files.when(() -> Files.createDirectories(tempDir.toPath())).thenThrow(new IOException());
reporter.setStatisticsFolder(tempDir);
reporterFlowProvider();
List<LoggingEvent> events = LOGGER.getLoggingEvents();
assertThat(events, hasSize(1));
LoggingEvent event = events.get(0);
assertEquals(String.format("Unable to write statistics.json into folder: %s", tempDir), event.getFormattedMessage());
assertThat(event.getThrowable().get(), instanceOf(IOException.class));
verify(runContext, times(36)).isRunCompleted();
verifyNoMoreInteractions(runContext);
}
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class KnownIssueProviderTests method testInitNoPropertyByQualifier.
@Test
void testInitNoPropertyByQualifier() throws IOException {
knownIssueProvider.setFileName(FILENAME);
ApplicationContext applicationContext = mock(ApplicationContext.class);
IPropertyParser propertyParser = mock(IPropertyParser.class);
knownIssueProvider.setApplicationContext(applicationContext);
knownIssueProvider.setFileName(FILENAME);
knownIssueProvider.setPropertyParser(propertyParser);
knownIssueProvider.setKnownIssueIdentifiers(new HashMap<>());
Resource resource = mock(Resource.class);
when(applicationContext.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + FILENAME)).thenReturn(new Resource[] { resource });
when(resource.getDescription()).thenReturn(FILENAME);
InputStream knownIssues = IOUtils.toInputStream(ResourceUtils.loadResource(KnownIssueProviderTests.class, FILENAME), StandardCharsets.UTF_8);
when(resource.getInputStream()).thenReturn(knownIssues);
when(propertyParser.getPropertyValue(PROPERTY_PREFIX, MAIN_PAGE_URL)).thenReturn(MAIN_PAGE_URL);
knownIssueProvider.init();
assertEquals(0, knownIssueProvider.getKnownIssueIdentifiers().size());
List<LoggingEvent> events = logger.getLoggingEvents();
assertEquals(2, events.size());
assertEquals(debug("Loading known issue identifiers from {}", FILENAME), events.get(0));
LoggingEvent info = events.get(1);
assertEquals("Issue with key {} filtered out by additional pattern '{}'. Actual property value is '{}'", info.getMessage());
assertEquals("ISSUE-123", info.getArguments().get(0));
assertEquals(".*examples.com", info.getArguments().get(1).toString());
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class TestInfoLoggerTests method shouldLogMetadata.
@ParameterizedTest
@MethodSource("sourceOfFailures")
@SuppressWarnings({ "MultipleStringLiterals", "MultipleStringLiteralsExtended" })
void shouldLogMetadata(String failuresMessage, List<Failure> failures) {
Statistic statistic = new Statistic();
statistic.incrementBroken();
statistic.incrementFailed();
statistic.incrementKnownIssue();
statistic.incrementPassed();
try (MockedStatic<StatisticsStoryReporter> reporter = mockStatic(StatisticsStoryReporter.class)) {
reporter.when(StatisticsStoryReporter::getStatistics).thenReturn(Map.of(NodeType.STORY, statistic, NodeType.SCENARIO, statistic, NodeType.STEP, statistic));
reporter.when(StatisticsStoryReporter::getFailures).thenReturn(failures);
TestInfoLogger.logEnvironmentMetadata();
ImmutableList<LoggingEvent> loggingEvents = LOGGER.getLoggingEvents();
assertThat(loggingEvents, hasSize(1));
assertThat(loggingEvents.get(0).getMessage(), matchesRegex("(?s)\\s+" + "-{60}\\s+" + " Configuration:\\s+" + "-{60}\\s+" + " Profile:\\s+" + "-{60}\\s+" + " Suite:\\s+" + "-{60}\\s+" + " Environment:\\s+" + "-{60}\\s+" + " Vividus:.*" + " Execution statistics:\\s+.+" + "-{40}\\s+" + " Story Scenario Step\\s+" + "-{40}\\s+" + "Passed 1 1 1\\s+" + "Failed 1 1 1\\s+" + "Broken 1 1 1\\s+" + "Known Issue 1 1 1\\s+" + "Pending 0 0 0\\s+" + "Skipped 0 0 0\\s+" + "-{40}\\s+" + "TOTAL 4 4 4" + failuresMessage));
}
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class SpelExpressionResolverTests method shouldLogAnExceptionAndReturnOriginalValue.
@Test
void shouldLogAnExceptionAndReturnOriginalValue() {
var expressionString = "#{anyOf(1,2,3)}";
assertEquals(expressionString, PARSER.resolve(expressionString));
var loggingEvents = LOGGER.getLoggingEvents();
assertThat(loggingEvents, Matchers.hasSize(1));
LoggingEvent event = loggingEvents.get(0);
assertEquals("Unable to evaluate the string '#{anyOf(1,2,3)}' as SpEL expression, it'll be used as is", event.getFormattedMessage());
assertInstanceOf(SpelEvaluationException.class, event.getThrowable().get());
}
Aggregations