Search in sources :

Example 1 with LoggingEvent

use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.

the class DescriptiveSoftAssertTests method testAssertThat.

@Test
void testAssertThat() {
    LoggingEvent expectedEvent = new LoggingEvent(Level.DEBUG, "Pass: {}", SYSTEM_DESCRIPTION + StringUtils.SPACE + "\"test\"");
    assertTrue(descriptiveSoftAssert.assertThat(BUSINESS_DESCRIPTION, SYSTEM_DESCRIPTION, TEST, equalTo(TEST)));
    verify(assertionCollection).addPassed();
    assertTrue(logger.getAllLoggingEvents().contains(expectedEvent));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Test(org.junit.jupiter.api.Test)

Example 2 with LoggingEvent

use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.

the class FilesystemScreenshotDebuggerTests method shouldLogIOException.

@Test
void shouldLogIOException() {
    File path = new File("route_66");
    filesystemScreenshotDebugger.setDebugScreenshotsLocation(Optional.of(path));
    filesystemScreenshotDebugger.debug(FilesystemScreenshotDebuggerTests.class, "", new BufferedImage(10, 10, 5));
    List<LoggingEvent> loggingEvents = testLogger.getLoggingEvents();
    LoggingEvent loggingEvent = loggingEvents.get(0);
    String message = loggingEvent.getMessage();
    assertThat(loggingEvents, Matchers.hasSize(1));
    assertEquals(Level.DEBUG, loggingEvent.getLevel());
    assertEquals("Unable to save debug screenshot to {}", message);
    assertThat(loggingEvent.getArguments().get(0).toString(), stringContainsInOrder(List.of(path.toString(), "FilesystemScreenshotDebuggerTests_.png")));
    assertThat(loggingEvent.getThrowable().get(), is(instanceOf(IIOException.class)));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test)

Example 3 with LoggingEvent

use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.

the class SshOutputPublisherTests method publishOutputWithError.

@Test
void publishOutputWithError() {
    String output = "fail";
    String error = "error";
    SshOutput sshOutput = new SshOutput();
    sshOutput.setOutputStream(output);
    sshOutput.setErrorStream(error);
    sshOutputPublisher.publishOutput(sshOutput);
    LoggingEvent outputLoggingEvent = verifyStdoutAttachmentPublishing(output);
    LoggingEvent errorLoggingEvent = verifyStderrAttachmentPublishing(error);
    verifyNoMoreInteractions(attachmentPublisher);
    assertThat(logger.getLoggingEvents(), equalTo(List.of(outputLoggingEvent, errorLoggingEvent)));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Test(org.junit.jupiter.api.Test)

Example 4 with LoggingEvent

use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.

the class XrayExporterTests method shouldFailIfMoreThanOneIdIsSpecified.

@Test
void shouldFailIfMoreThanOneIdIsSpecified() throws URISyntaxException, IOException {
    URI jsonResultsUri = getJsonResultsUri("morethanoneid");
    xrayExporterOptions.setJsonResultsDirectory(Paths.get(jsonResultsUri));
    xrayExporter.exportResults();
    List<LoggingEvent> loggingEvents = new ArrayList<>(logger.getLoggingEvents());
    LoggingEvent errorEvent = loggingEvents.remove(2);
    assertEquals(ERROR_MESSAGE, errorEvent.getMessage());
    Optional<Throwable> eventThorable = errorEvent.getThrowable();
    assertTrue(eventThorable.isPresent());
    Throwable throwable = eventThorable.get();
    assertThat(throwable, instanceOf(NotUniqueMetaValueException.class));
    String errorMessage = "Expected only one value for the 'testCaseId' meta, but got: STUB-0, STUB-1, STUB-2";
    assertEquals(errorMessage, throwable.getMessage());
    validateLogs(loggingEvents, jsonResultsUri, getExportingScenarioEvent(), getReportErrorEvent(errorMessage));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) ArrayList(java.util.ArrayList) NotUniqueMetaValueException(org.vividus.model.jbehave.NotUniqueMetaValueException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 5 with LoggingEvent

use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.

the class TestCaseParserTests method testCreateTestCases.

@Test
void testCreateTestCases() 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.SKIPPED, TestCaseStatus.PASSED));
    List<TestCase> testCases = testCaseParser.createTestCases(objectMapper);
    assertEquals(testCases.size(), 2);
    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).getMessage(), is(FOR_EXPORTING_STRING));
    assertThat(events.get(2).getLevel(), is(Level.INFO));
    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)

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