|
1 | 1 | package io.github.dmitrysulman.logback.access.reactor.netty.autoconfigure |
2 | 2 |
|
| 3 | +import ch.qos.logback.core.status.OnConsoleStatusListener |
3 | 4 | import io.github.dmitrysulman.logback.access.reactor.netty.ReactorNettyAccessLogFactory |
| 5 | +import io.kotest.matchers.booleans.shouldBeTrue |
4 | 6 | import io.mockk.mockk |
5 | 7 | import io.mockk.verify |
6 | 8 | import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat |
@@ -59,6 +61,55 @@ class ReactorNettyAccessLogFactoryAutoConfigurationTests { |
59 | 61 | } |
60 | 62 | } |
61 | 63 |
|
| 64 | + @Test |
| 65 | + fun `should supply beans when explicitly enabled by the property`() { |
| 66 | + ReactiveWebApplicationContextRunner() |
| 67 | + .withConfiguration(AutoConfigurations.of(ReactorNettyAccessLogFactoryAutoConfiguration::class.java)) |
| 68 | + .withPropertyValues("logback.access.reactor.netty.enabled=true") |
| 69 | + .run { context -> |
| 70 | + assertThat(context).hasSingleBean(ReactorNettyAccessLogFactory::class.java) |
| 71 | + assertThat(context).hasSingleBean(ReactorNettyAccessLogWebServerFactoryCustomizer::class.java) |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun `should enable debug mode by the property`() { |
| 77 | + ReactiveWebApplicationContextRunner() |
| 78 | + .withConfiguration(AutoConfigurations.of(ReactorNettyAccessLogFactoryAutoConfiguration::class.java)) |
| 79 | + .withPropertyValues("logback.access.reactor.netty.debug=true") |
| 80 | + .run { context -> |
| 81 | + val factory = context.getBean<ReactorNettyAccessLogFactory>() |
| 82 | + factory.accessContext.statusManager.copyOfStatusListenerList |
| 83 | + .any { it::class == OnConsoleStatusListener::class } |
| 84 | + .shouldBeTrue() |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + fun `should not enable debug mode when debug false`() { |
| 90 | + ReactiveWebApplicationContextRunner() |
| 91 | + .withConfiguration(AutoConfigurations.of(ReactorNettyAccessLogFactoryAutoConfiguration::class.java)) |
| 92 | + .withPropertyValues("logback.access.reactor.netty.debug=false") |
| 93 | + .run { context -> |
| 94 | + val factory = context.getBean<ReactorNettyAccessLogFactory>() |
| 95 | + factory.accessContext.statusManager.copyOfStatusListenerList |
| 96 | + .none { it::class == OnConsoleStatusListener::class } |
| 97 | + .shouldBeTrue() |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + fun `should not enable debug mode when no debug property provided`() { |
| 103 | + ReactiveWebApplicationContextRunner() |
| 104 | + .withConfiguration(AutoConfigurations.of(ReactorNettyAccessLogFactoryAutoConfiguration::class.java)) |
| 105 | + .run { context -> |
| 106 | + val factory = context.getBean<ReactorNettyAccessLogFactory>() |
| 107 | + factory.accessContext.statusManager.copyOfStatusListenerList |
| 108 | + .none { it::class == OnConsoleStatusListener::class } |
| 109 | + .shouldBeTrue() |
| 110 | + } |
| 111 | + } |
| 112 | + |
62 | 113 | @Test |
63 | 114 | fun `should not supply beans when already has user defined beans in the context`() { |
64 | 115 | ReactiveWebApplicationContextRunner() |
|
0 commit comments