Skip to content

Commit

Permalink
[vividus] Rename o.v.report.MetadataLogger into o.v.log.TestInfoLogger (
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski committed Jan 27, 2022
1 parent 8b35d2d commit a8b86c6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions vividus/src/main/java/org/vividus/configuration/Vividus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@

import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;
import org.vividus.util.json.JsonPathUtils;

import io.github.classgraph.ClassGraph;
Expand All @@ -44,7 +44,7 @@ public static void init()
configureLog4j2();
createJulToSlf4jBridge();
configureFreemarkerLogger();
MetadataLogger.drawBanner();
TestInfoLogger.drawBanner();
BeanFactory.open();

// Load JsonPathUtils to configure JsonPath SPI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.vividus.report;
package org.vividus.log;

import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -42,20 +42,20 @@
import de.vandermeer.asciitable.CWC_LongestLine;
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment;

public final class MetadataLogger
public final class TestInfoLogger
{
private static final int MAX_CELL_WIDTH = 50;
private static final int MARGIN = 3;
private static final String HYPHEN = "-";
private static final int HEADER_SIZE = 40;
private static final String CATEGORY_FORMAT = "%s%n %s:%n";
private static final String NEW_LINE = "%n";
private static final Logger LOGGER = LoggerFactory.getLogger(MetadataLogger.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TestInfoLogger.class);
private static final Pattern SECURE_KEY_PATTERN = Pattern
.compile(".*(password|((access|api|private)-)?(key|secret|token)).*", Pattern.CASE_INSENSITIVE);
private static final int HORIZONTAL_RULE_LENGTH = 60;

private MetadataLogger()
private TestInfoLogger()
{
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public static void logPropertiesSecurely(Properties properties)
.stream()
.map(e -> Map.entry((String) e.getKey(), e.getValue()))
.sorted(Entry.comparingByKey())
.forEach(MetadataLogger::logPropertySecurely);
.forEach(TestInfoLogger::logPropertySecurely);
}

private static void logPropertySecurely(Entry<String, Object> entry)
Expand Down
6 changes: 3 additions & 3 deletions vividus/src/main/java/org/vividus/runner/GenericRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.vividus.Status;
import org.vividus.configuration.BeanFactory;
import org.vividus.configuration.Vividus;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;

public class GenericRunner extends JUnitStories
{
Expand All @@ -57,8 +57,8 @@ public GenericRunner()
Vividus.init();
batchedPathFinder = BeanFactory.getBean(IBatchedPathFinder.class);
embedder = BeanFactory.getBean(embedderBeanName, Embedder.class);
MetadataLogger.logPropertiesSecurely(System.getProperties());
MetadataLogger.logPropertiesSecurely(BeanFactory.getBean("properties", Properties.class));
TestInfoLogger.logPropertiesSecurely(System.getProperties());
TestInfoLogger.logPropertiesSecurely(BeanFactory.getBean("properties", Properties.class));
}

protected static void setEmbedderBeanName(String embedderBeanName)
Expand Down
6 changes: 3 additions & 3 deletions vividus/src/main/java/org/vividus/steps/SetupSteps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,13 @@
package org.vividus.steps;

import org.jbehave.core.annotations.AfterStories;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;

public class SetupSteps
{
@AfterStories
public void afterStories()
{
MetadataLogger.logEnvironmentMetadata();
TestInfoLogger.logEnvironmentMetadata();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@
import org.mockito.MockedConstruction;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ResourceList;
Expand All @@ -41,7 +41,7 @@ class VividusTests
void shouldDrawBannerAfterLoggerConfigurations()
{
try (MockedStatic<BeanFactory> beanFactory = mockStatic(BeanFactory.class);
MockedStatic<MetadataLogger> metadataLogger = mockStatic(MetadataLogger.class);
MockedStatic<TestInfoLogger> metadataLogger = mockStatic(TestInfoLogger.class);
MockedConstruction<ClassGraph> classGraph = mockConstruction(ClassGraph.class, (mock, context) -> {
when(mock.acceptPackagesNonRecursive("")).thenReturn(mock);
ScanResult scanResult = Mockito.mock(ScanResult.class);
Expand All @@ -53,7 +53,7 @@ void shouldDrawBannerAfterLoggerConfigurations()
List<ClassGraph> constructedScanners = classGraph.constructed();
assertThat(constructedScanners, hasSize(1));
verify(classGraph.constructed().get(0)).scan();
metadataLogger.verify(MetadataLogger::drawBanner);
metadataLogger.verify(TestInfoLogger::drawBanner);
beanFactory.verify(BeanFactory::open);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.vividus.report;
package org.vividus.log;

import static com.github.valfirst.slf4jtest.LoggingEvent.info;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -54,9 +54,9 @@
import org.vividus.util.ResourceUtils;

@ExtendWith(TestLoggerFactoryExtension.class)
class MetadataLoggerTests
class TestInfoLoggerTests
{
private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(MetadataLogger.class);
private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(TestInfoLogger.class);
private static final String FORMAT = "{}={}";
private static final String MESSAGE = "This is a very long message that should be wrapped to defined cell size "
+ "and with special char: %";
Expand All @@ -74,7 +74,7 @@ void testLogPropertiesSecurely(String key)
{
Properties properties = new Properties();
properties.put(key, "value");
MetadataLogger.logPropertiesSecurely(properties);
TestInfoLogger.logPropertiesSecurely(properties);
assertThat(LOGGER.getLoggingEvents(), is(List.of(info(FORMAT, key, "****"))));
}

Expand All @@ -88,7 +88,7 @@ void testLogPropertiesSecurelyPlainProperties()
Properties properties = new Properties();
properties.put(keyString, valueString);
properties.put(keyInt, valueInt);
MetadataLogger.logPropertiesSecurely(properties);
TestInfoLogger.logPropertiesSecurely(properties);
assertThat(LOGGER.getLoggingEvents(), is(List.of(
info(FORMAT, keyString, valueString),
info(FORMAT, keyInt, valueInt)
Expand Down Expand Up @@ -135,7 +135,7 @@ void shouldLogMetadata(String failuresMessage, List<Failure> failures)
NodeType.SCENARIO, statistic,
NodeType.STEP, statistic));
reporter.when(StatisticsStoryReporter::getFailures).thenReturn(failures);
MetadataLogger.logEnvironmentMetadata();
TestInfoLogger.logEnvironmentMetadata();
ImmutableList<LoggingEvent> loggingEvents = LOGGER.getLoggingEvents();
assertThat(loggingEvents, hasSize(1));
assertThat(loggingEvents.get(0).getMessage(), matchesRegex(
Expand Down Expand Up @@ -180,7 +180,7 @@ private static Failure createFailure(String storyName, String scenatioTitle, Str
@Test
void shouldPrintBanner()
{
MetadataLogger.drawBanner();
TestInfoLogger.drawBanner();
assertThat(LOGGER.getLoggingEvents(), is(List.of(info("\n{}", ResourceUtils.loadResource("banner.vividus")))));
}
}
10 changes: 5 additions & 5 deletions vividus/src/test/java/org/vividus/runner/GenericRunnerTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@
import org.vividus.IBatchedPathFinder;
import org.vividus.configuration.BeanFactory;
import org.vividus.configuration.Vividus;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;

class GenericRunnerTests
{
Expand All @@ -39,7 +39,7 @@ void shouldPerformInitInInstanceInitializationBlock()
GenericRunner.setEmbedderBeanName(embedderBeanName);
try (MockedStatic<Vividus> vividus = mockStatic(Vividus.class);
MockedStatic<BeanFactory> beanFactory = mockStatic(BeanFactory.class);
MockedStatic<MetadataLogger> metadataLogger = mockStatic(MetadataLogger.class))
MockedStatic<TestInfoLogger> metadataLogger = mockStatic(TestInfoLogger.class))
{
IBatchedPathFinder batchedPathFinder = mock(IBatchedPathFinder.class);
beanFactory.when(() -> BeanFactory.getBean(IBatchedPathFinder.class)).thenReturn(batchedPathFinder);
Expand All @@ -51,8 +51,8 @@ void shouldPerformInitInInstanceInitializationBlock()
GenericRunner genericRunner = new GenericRunner();
assertEquals(embedder, genericRunner.configuredEmbedder());
vividus.verify(Vividus::init);
metadataLogger.verify(() -> MetadataLogger.logPropertiesSecurely(systemProperties));
metadataLogger.verify(() -> MetadataLogger.logPropertiesSecurely(springProperties));
metadataLogger.verify(() -> TestInfoLogger.logPropertiesSecurely(systemProperties));
metadataLogger.verify(() -> TestInfoLogger.logPropertiesSecurely(springProperties));
}
}
}
8 changes: 4 additions & 4 deletions vividus/src/test/java/org/vividus/steps/SetupStepsTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,17 +20,17 @@

import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.vividus.report.MetadataLogger;
import org.vividus.log.TestInfoLogger;

class SetupStepsTests
{
@Test
void shouldLogEnvironmentMetadataAfterStories()
{
try (MockedStatic<MetadataLogger> metadataLogger = mockStatic(MetadataLogger.class))
try (MockedStatic<TestInfoLogger> metadataLogger = mockStatic(TestInfoLogger.class))
{
new SetupSteps().afterStories();
metadataLogger.verify(MetadataLogger::logEnvironmentMetadata);
metadataLogger.verify(TestInfoLogger::logEnvironmentMetadata);
}
}
}

0 comments on commit a8b86c6

Please sign in to comment.