-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into automated/sync-docs-release-4.0.0-to-develop
- Loading branch information
Showing
12 changed files
with
244 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
code/generators/src/main/java/dev/inditex/karate/openapi/OpenApiGeneratorANSILogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dev.inditex.karate.openapi; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The Class ANSILogger. | ||
*/ | ||
public class OpenApiGeneratorANSILogger { | ||
|
||
/** The Constant OPEN_API_GENERATOR_STDOUT. */ | ||
protected static final Logger OPEN_API_GENERATOR_STDOUT = LoggerFactory.getLogger("OpenApiGenerator"); | ||
|
||
/** The Constant ANSI_RESET. */ | ||
protected static final String ANSI_RESET = "\u001B[0m"; | ||
|
||
/** The Constant ANSI_BLUE. */ | ||
protected static final String ANSI_BLUE = "\u001B[34m"; | ||
|
||
/** The Constant ANSI_YELLOW. */ | ||
protected static final String ANSI_YELLOW = "\u001B[33m"; | ||
|
||
/** The Constant ANSI_RED. */ | ||
protected static final String ANSI_RED = "\u001B[31m"; | ||
|
||
/** The Constant LOG_FORMAT. */ | ||
protected static final String LOG_FORMAT = "\n{}{}{}{}\n"; | ||
|
||
/** | ||
* Instantiates a new ANSI logger. | ||
*/ | ||
protected OpenApiGeneratorANSILogger() { | ||
// Empty | ||
} | ||
|
||
/** | ||
* Info. | ||
* | ||
* @param message the message | ||
*/ | ||
public static void info(final String message) { | ||
OPEN_API_GENERATOR_STDOUT.info(LOG_FORMAT, ANSI_BLUE, "INFO - ", message, ANSI_RESET); | ||
} | ||
|
||
/** | ||
* Warn. | ||
* | ||
* @param message the message | ||
*/ | ||
public static void warn(final String message) { | ||
OPEN_API_GENERATOR_STDOUT.warn(LOG_FORMAT, ANSI_YELLOW, "WARN - ", message, ANSI_RESET); | ||
} | ||
|
||
/** | ||
* Error. | ||
* | ||
* @param message the message | ||
*/ | ||
public static void error(final String message) { | ||
OPEN_API_GENERATOR_STDOUT.error(LOG_FORMAT, ANSI_RED, "ERROR - ", message, ANSI_RESET); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
code/generators/src/test/java/dev/inditex/karate/openapi/OpenApiGeneratorANSILoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package dev.inditex.karate.openapi; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.LoggerFactory; | ||
|
||
class OpenApiGeneratorANSILoggerTest { | ||
|
||
protected ListAppender<ILoggingEvent> logWatcher; | ||
|
||
protected Level defaultLogLevel; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
defaultLogLevel = ((Logger) LoggerFactory.getLogger("OpenApiGenerator")).getLevel(); | ||
logWatcher = new ListAppender<>(); | ||
logWatcher.start(); | ||
((Logger) LoggerFactory.getLogger("OpenApiGenerator")).addAppender(logWatcher); | ||
((Logger) LoggerFactory.getLogger("OpenApiGenerator")).setLevel(Level.INFO); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
((Logger) LoggerFactory.getLogger("OpenApiGenerator")).detachAppender(logWatcher); | ||
((Logger) LoggerFactory.getLogger("OpenApiGenerator")).setLevel(defaultLogLevel); | ||
} | ||
|
||
@Nested | ||
class Constructor { | ||
@Test | ||
void when_instance_expect_no_exception() { | ||
assertThatCode(OpenApiGeneratorANSILogger::new).doesNotThrowAnyException(); | ||
} | ||
} | ||
|
||
@Nested | ||
class Info { | ||
@Test | ||
void when_message_expect_delegate_to_logger_with_color() { | ||
final String message = "message"; | ||
OpenApiGeneratorANSILogger.info(message); | ||
|
||
assertThat(logWatcher.list).hasSize(1).extracting("level").containsOnly(Level.INFO); | ||
assertThat(logWatcher.list.get(0).getFormattedMessage()) | ||
.contains(OpenApiGeneratorANSILogger.ANSI_BLUE + "INFO - " + message + OpenApiGeneratorANSILogger.ANSI_RESET); | ||
|
||
} | ||
} | ||
|
||
@Nested | ||
class Warn { | ||
@Test | ||
void when_message_expect_delegate_to_logger_with_color() { | ||
final String message = "message"; | ||
OpenApiGeneratorANSILogger.warn(message); | ||
|
||
assertThat(logWatcher.list).hasSize(1).extracting("level").containsOnly(Level.WARN); | ||
assertThat(logWatcher.list.get(0).getFormattedMessage()) | ||
.contains(OpenApiGeneratorANSILogger.ANSI_YELLOW + "WARN - " + message + OpenApiGeneratorANSILogger.ANSI_RESET); | ||
} | ||
} | ||
|
||
@Nested | ||
class Error { | ||
@Test | ||
void when_message_expect_delegate_to_logger_with_color() { | ||
final String message = "message"; | ||
OpenApiGeneratorANSILogger.error(message); | ||
|
||
assertThat(logWatcher.list).hasSize(1).extracting("level").containsOnly(Level.ERROR); | ||
assertThat(logWatcher.list.get(0).getFormattedMessage()) | ||
.contains(OpenApiGeneratorANSILogger.ANSI_RED + "ERROR - " + message + OpenApiGeneratorANSILogger.ANSI_RESET); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.