Search in sources :

Example 6 with LoggingEvent

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));
}
Also used : Path(java.nio.file.Path) LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) TestCase(org.vividus.zephyr.model.TestCase) Test(org.junit.jupiter.api.Test)

Example 7 with LoggingEvent

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);
    }
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) IOException(java.io.IOException) Files(java.nio.file.Files) Test(org.junit.jupiter.api.Test)

Example 8 with LoggingEvent

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());
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) ApplicationContext(org.springframework.context.ApplicationContext) IPropertyParser(org.vividus.util.property.IPropertyParser) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) Test(org.junit.jupiter.api.Test)

Example 9 with LoggingEvent

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));
    }
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) StatisticsStoryReporter(org.vividus.StatisticsStoryReporter) Statistic(org.vividus.model.Statistic) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with LoggingEvent

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());
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Test(org.junit.jupiter.api.Test)

Aggregations

LoggingEvent (com.github.valfirst.slf4jtest.LoggingEvent)18 Test (org.junit.jupiter.api.Test)17 Scope (io.opentracing.Scope)2 Span (io.opentracing.Span)2 MockSpan (io.opentracing.mock.MockSpan)2 BufferedImage (java.awt.image.BufferedImage)2 Path (java.nio.file.Path)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TestCase (org.vividus.zephyr.model.TestCase)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 Component (net.kyori.adventure.text.Component)1