Skip to content

responsibleapi/test-kotlin-vertx

Repository files navigation

Kotlin Vert.x test helper

Validates Vert.x responses against OpenAPI schema

Usage

In build.gradle:

repositories {
    maven {
        url "https://jitpack.io"
        content {
            includeGroup "com.github.responsibleapi"
        }
    }
}

dependencies {
    testImplementation "com.github.responsibleapi:test-kotlin-vertx:X.X.X"
}

Assuming you have:

  • A verticle called App
  • Spec at src/main/resources/openapi.json

here's how responses are validated:

class AppTest {

    private companion object {
        val vertx = Vertx.vertx()!!

        val port = (40000..50000).random()

        @JvmStatic
        @BeforeAll
        fun setUp(): Unit = runBlocking {
            vertx.deployVerticle(
                App(port = port)
            ).coAwait()
        }

        val client: WebClient = WebClient.create(
            vertx,
            WebClientOptions()
                .setDefaultHost("localhost")
                .setDefaultPort(port)
        )
        val rb = runBlocking {
            RouterBuilder.create(vertx, "openapi.json").coAwait()
        }
        val responsible = Responsible(rb.openAPI.openAPI, client)

        @JvmStatic
        @AfterAll
        fun tearDown() {
            vertx.close()
        }
    }

    @Test
    fun `show not found`() = vertx.test {
        responsible.check(
            req = rb.operation("getShow2")
                .toRequest(pathParams = mapOf("show_id" to genID(length = 11))),
            status = 404,
        )
    }
}

Requests are validated by Vert.x itself


ResponsibleAPI is a compact language that compiles to OpenAPI: https://responsibleapi.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages