Skip to content

Commit

Permalink
Add loglevel to Hoverfly JUnit5 config
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Jul 19, 2019
1 parent 41918b1 commit 4a7e973
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/pages/corefunctionality/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ If you are developing behind a cooperate proxy, you can configure Hoverfly to us
Logging
-------
Hoverfly logs to SLF4J by default, meaning that you have control of Hoverfly logs using JAVA logging framework.
Here is an example ``logback.xml`` that directs Hoverfly WARN logs to the console:
Here is an example ``logback.xml`` that directs Hoverfly ``WARN`` logs to the console:

.. code-block:: xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static io.specto.hoverfly.junit.core.HoverflyConfig getHoverflyConfigs(HoverflyC
configs = localConfigs()
.sslCertificatePath(config.sslCertificatePath())
.sslKeyPath(config.sslKeyPath())
.upstreamProxy(config.upstreamProxy());
.upstreamProxy(config.upstreamProxy())
.logLevel(config.logLevel());
if (config.plainHttpTunneling()) {
((LocalHoverflyConfig) configs).plainHttpTunneling();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.specto.hoverfly.junit.core.SimulationPreprocessor;
import io.specto.hoverfly.junit.core.config.LocalHoverflyConfig;
import io.specto.hoverfly.junit.core.config.LogLevel;
import io.specto.hoverfly.junit.core.config.RemoteHoverflyConfig;

import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -92,4 +93,9 @@
* Set additional commands for starting Hoverfly
*/
String[] commands() default {};

/**
* Set Hoverfly log level
*/
LogLevel logLevel() default LogLevel.INFO;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import io.specto.hoverfly.junit.core.HoverflyMode;
import io.specto.hoverfly.junit.core.SimulationPreprocessor;
import io.specto.hoverfly.junit.core.config.HoverflyConfiguration;
import io.specto.hoverfly.junit.core.config.LogLevel;
import io.specto.hoverfly.junit.core.model.Simulation;
import io.specto.hoverfly.junit5.api.HoverflyConfig;
import io.specto.hoverfly.junit5.api.HoverflyCore;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;


Expand Down Expand Up @@ -40,6 +43,7 @@ void shouldUseDefaultValues(Hoverfly hoverfly) {
assertThat(configs.isStatefulCapture()).isFalse();
assertThat(configs.getSimulationPreprocessor()).isEmpty();
assertThat(configs.getCommands()).isEmpty();
assertThat(configs.getLogLevel()).isEqualTo(Optional.of(LogLevel.INFO));
}
}

Expand All @@ -49,7 +53,8 @@ void shouldUseDefaultValues(Hoverfly hoverfly) {
plainHttpTunneling = true, disableTlsVerification = true, upstreamProxy = "localhost:5000",
webServer = true, statefulCapture = true,
simulationPreprocessor = CustomSimulationPreprocessor.class,
commands = { "-log-level", "error" }
commands = { "-log-level", "error" },
logLevel = LogLevel.DEBUG
))
@ExtendWith(HoverflyExtension.class)
class CustomizedSettings {
Expand All @@ -69,6 +74,7 @@ void shouldUseCustomizedValues(Hoverfly hoverfly) {
assertThat(configs.isStatefulCapture()).isTrue();
assertThat(configs.getSimulationPreprocessor()).isPresent();
assertThat(configs.getCommands()).containsExactly("-log-level", "error");
assertThat(configs.getLogLevel()).isEqualTo(Optional.of(LogLevel.DEBUG));
}

}
Expand Down

0 comments on commit 4a7e973

Please sign in to comment.