|
| 1 | +package dev.akkinoc.spring.boot.logback.access |
| 2 | + |
| 3 | +import dev.akkinoc.spring.boot.logback.access.test.assertion.Assertions |
| 4 | +import dev.akkinoc.spring.boot.logback.access.test.extension.EventsCapture |
| 5 | +import dev.akkinoc.spring.boot.logback.access.test.extension.EventsCaptureExtension |
| 6 | +import dev.akkinoc.spring.boot.logback.access.test.type.JettyReactiveWebTest |
| 7 | +import dev.akkinoc.spring.boot.logback.access.test.type.JettyServletWebTest |
| 8 | +import dev.akkinoc.spring.boot.logback.access.test.type.TomcatReactiveWebTest |
| 9 | +import dev.akkinoc.spring.boot.logback.access.test.type.TomcatServletWebTest |
| 10 | +import dev.akkinoc.spring.boot.logback.access.test.type.UndertowReactiveWebTest |
| 11 | +import dev.akkinoc.spring.boot.logback.access.test.type.UndertowServletWebTest |
| 12 | +import io.kotest.matchers.collections.shouldBeSingleton |
| 13 | +import io.kotest.matchers.shouldBe |
| 14 | +import org.junit.jupiter.api.Test |
| 15 | +import org.junit.jupiter.api.extension.ExtendWith |
| 16 | +import org.springframework.beans.factory.annotation.Autowired |
| 17 | +import org.springframework.boot.test.web.client.TestRestTemplate |
| 18 | +import org.springframework.boot.test.web.client.exchange |
| 19 | +import org.springframework.http.RequestEntity |
| 20 | +import org.springframework.test.context.TestPropertySource |
| 21 | + |
| 22 | +/** |
| 23 | + * Tests the case where the location of the configuration file is specified. |
| 24 | + */ |
| 25 | +@ExtendWith(EventsCaptureExtension::class) |
| 26 | +sealed class ConfigurationFileLocationTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `Appends a Logback-access event according to the configuration file found`( |
| 30 | + @Autowired rest: TestRestTemplate, |
| 31 | + capture: EventsCapture, |
| 32 | + ) { |
| 33 | + val request = RequestEntity.get("/mock-controller/text").build() |
| 34 | + val response = rest.exchange<String>(request) |
| 35 | + response.statusCodeValue.shouldBe(200) |
| 36 | + Assertions.assertLogbackAccessEventsEventually { capture.shouldBeSingleton() } |
| 37 | + } |
| 38 | + |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Tests the case where the location of the configuration file is specified as a file system path. |
| 43 | + */ |
| 44 | +@TestPropertySource(properties = ["logback.access.config=target/test-classes/logback-access-test.capture.xml"]) |
| 45 | +sealed class ConfigurationFilePathTest : ConfigurationFileLocationTest() |
| 46 | + |
| 47 | +/** |
| 48 | + * Tests the [ConfigurationFilePathTest] using the Tomcat servlet web server. |
| 49 | + */ |
| 50 | +@TomcatServletWebTest |
| 51 | +class TomcatServletWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 52 | + |
| 53 | +/** |
| 54 | + * Tests the [ConfigurationFilePathTest] using the Tomcat reactive web server. |
| 55 | + */ |
| 56 | +@TomcatReactiveWebTest |
| 57 | +class TomcatReactiveWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 58 | + |
| 59 | +/** |
| 60 | + * Tests the [ConfigurationFilePathTest] using the Jetty servlet web server. |
| 61 | + */ |
| 62 | +@JettyServletWebTest |
| 63 | +class JettyServletWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 64 | + |
| 65 | +/** |
| 66 | + * Tests the [ConfigurationFilePathTest] using the Jetty reactive web server. |
| 67 | + */ |
| 68 | +@JettyReactiveWebTest |
| 69 | +class JettyReactiveWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 70 | + |
| 71 | +/** |
| 72 | + * Tests the [ConfigurationFilePathTest] using the Undertow servlet web server. |
| 73 | + */ |
| 74 | +@UndertowServletWebTest |
| 75 | +class UndertowServletWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 76 | + |
| 77 | +/** |
| 78 | + * Tests the [ConfigurationFilePathTest] using the Undertow reactive web server. |
| 79 | + */ |
| 80 | +@UndertowReactiveWebTest |
| 81 | +class UndertowReactiveWebConfigurationFilePathTest : ConfigurationFilePathTest() |
| 82 | + |
| 83 | +/** |
| 84 | + * Tests the case where the location of the configuration file is specified as a file scheme URI. |
| 85 | + */ |
| 86 | +@TestPropertySource(properties = ["logback.access.config=file:target/test-classes/logback-access-test.capture.xml"]) |
| 87 | +sealed class ConfigurationFileUriTest : ConfigurationFileLocationTest() |
| 88 | + |
| 89 | +/** |
| 90 | + * Tests the [ConfigurationFileUriTest] using the Tomcat servlet web server. |
| 91 | + */ |
| 92 | +@TomcatServletWebTest |
| 93 | +class TomcatServletWebConfigurationFileUriTest : ConfigurationFileUriTest() |
| 94 | + |
| 95 | +/** |
| 96 | + * Tests the [ConfigurationFileUriTest] using the Tomcat reactive web server. |
| 97 | + */ |
| 98 | +@TomcatReactiveWebTest |
| 99 | +class TomcatReactiveWebConfigurationFileUriTest : ConfigurationFileUriTest() |
| 100 | + |
| 101 | +/** |
| 102 | + * Tests the [ConfigurationFileUriTest] using the Jetty servlet web server. |
| 103 | + */ |
| 104 | +@JettyServletWebTest |
| 105 | +class JettyServletWebConfigurationFileUriTest : ConfigurationFileUriTest() |
| 106 | + |
| 107 | +/** |
| 108 | + * Tests the [ConfigurationFileUriTest] using the Jetty reactive web server. |
| 109 | + */ |
| 110 | +@JettyReactiveWebTest |
| 111 | +class JettyReactiveWebConfigurationFileUriTest : ConfigurationFileUriTest() |
| 112 | + |
| 113 | +/** |
| 114 | + * Tests the [ConfigurationFileUriTest] using the Undertow servlet web server. |
| 115 | + */ |
| 116 | +@UndertowServletWebTest |
| 117 | +class UndertowServletWebConfigurationFileUriTest : ConfigurationFileUriTest() |
| 118 | + |
| 119 | +/** |
| 120 | + * Tests the [ConfigurationFileUriTest] using the Undertow reactive web server. |
| 121 | + */ |
| 122 | +@UndertowReactiveWebTest |
| 123 | +class UndertowReactiveWebConfigurationFileUriTest : ConfigurationFileUriTest() |
0 commit comments