Hello I have a spring cloud gateway service, writ...
# help
o
Hello I have a spring cloud gateway service, written in kotlin, where I am defining a
SecurityWebFilterChain
that define some rules for different endpoints in terms of authentication/authorization. The service itself does not contain any controllers/routes. I am trying to come up with a up to test such config so whenever a new endpoint rule is added, the test run to make sure nothing else is broken. Setup: spring boot: v2.7.14 kotlin version: 1.7.21 java version: 17 wiremock: 3.2.0 and I added the following sample test
Copy code
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.reactive.server.WebTestClient

@SpringBootTest
@ContextConfiguration(classes = [SecurityConfig::class]) // That's config class containing a SecurityWebFilterChain
class SecurityConfigTest {

    private val mockServer = WireMockServer(4567)

    private val webTestClient = WebTestClient.bindToServer()
        .baseUrl("<http://localhost:4567/>")
        .build()

    @BeforeEach
    fun setUp() {
        mockServer.start()
    }

    @AfterEach
    fun tearDown() {
        mockServer.stop()
    }

    @Test
    fun testGetRequest() {
        mockServer.stubFor(
            WireMock.get("/api/users").willReturn(
                WireMock.aResponse().withBody("""{"users": [{"id": 1, "name": "John Doe"}]}""")
            )
        )

        webTestClient.get().uri("/api/users")
            .exchange()
            .expectStatus().isOk
            .expectBody().json("""{"users": [{"id": 1, "name": "John Doe"}]}""")
    }
}
Upon running the test, I get the following error
java.lang.NoSuchMethodError: 'void org.eclipse.jetty.server.NetworkTrafficServerConnector.setNetworkTrafficListener(org.eclipse.jetty.io.NetworkTrafficListener)'
Upon further investigation, I tried to upgrade the jetty-server to
10.0.10
as the current one used by wiremock is
9.4.51.v20230217
. I got a different error which is
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/component/AbstractLifeCycle$StopException
Questions: • Is the above approach correct? • Are the dependencies version correct or is there some conflict?