package com.felipecosta.microservice.server

import com.felipecosta.microservice.server.frontcontroller.FrontCommand
import org.junit.Test
import java.net.HttpURLConnection
import java.net.URL
import kotlin.test.assertEquals

class SparkServerHandlerTest {

    @Test
    fun givenHandlerWhenGetItShouldAssertResponse() {
        val stubFrontCommand = object : FrontCommand() {
            override fun process() {
                render(text = "SparkServerHandler Integration Test")
            }
        }
        SparkServerHandler().apply {
            get(GetHandler(Path("/"), { stubFrontCommand }))
        }

        spark.Spark.awaitInitialization()

        val urlConnection = (URL("http://localhost:8080").openConnection() as HttpURLConnection).apply {
            readTimeout = 2000
            connectTimeout = 2000
            requestMethod = "GET"
        }
        val response = urlConnection.inputStream.reader().use { it.readText() }

        assertEquals("SparkServerHandler Integration Test", response)

        spark.Spark.stop()
    }
}
Create the integration test of SparkServerHandler
Create the integration test of SparkServerHandler

It follows this approach: https://8thlight.com/blog/eric-smith/2011/10/27/thats-not-yours.html

fcostaa/kotlin-microservice,fcostaa/kotlin-microservice,fcostaa/kotlin-microservice