add ADRs for gradle and spring boot version and version smoke-tests
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package de.hoennig.gittally.framework
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
|
||||
interface Greeter {
|
||||
fun greet(name: String): String
|
||||
}
|
||||
|
||||
class MockKSmokeTest : FunSpec({
|
||||
|
||||
test("mockk stubs and verifies") {
|
||||
val greeter = mockk<Greeter>()
|
||||
every { greeter.greet("world") } returns "hello, world"
|
||||
|
||||
greeter.greet("world") shouldBe "hello, world"
|
||||
|
||||
verify(exactly = 1) { greeter.greet("world") }
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
package de.hoennig.gittally.framework
|
||||
|
||||
import com.ninjasquad.springmockk.MockkBean
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.clearMocks
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Import
|
||||
|
||||
interface MessageService {
|
||||
fun getMessage(): String
|
||||
}
|
||||
|
||||
/** Workaround for springmockk incompatibility: register MockK mock via @TestConfiguration. */
|
||||
@SpringBootTest
|
||||
@Import(SpringMockKSmokeTest.Mocks::class)
|
||||
class SpringMockKSmokeTest : FunSpec() {
|
||||
|
||||
@TestConfiguration
|
||||
class Mocks {
|
||||
@Bean
|
||||
fun messageService(): MessageService = mockk()
|
||||
}
|
||||
|
||||
@Autowired
|
||||
lateinit var messageService: MessageService
|
||||
|
||||
init {
|
||||
beforeEach { clearMocks(messageService) }
|
||||
|
||||
test("MockK mock registered as Spring bean can be stubbed and verified") {
|
||||
every { messageService.getMessage() } returns "hello from mock"
|
||||
|
||||
messageService.getMessage() shouldBe "hello from mock"
|
||||
|
||||
verify(exactly = 1) { messageService.getMessage() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Verifies whether @MockkBean works with the current Spring Boot version (springmockk 4.0.2). */
|
||||
@SpringBootTest
|
||||
class MockkBeanSmokeTest : FunSpec() {
|
||||
|
||||
@MockkBean
|
||||
lateinit var messageService: MessageService
|
||||
|
||||
init {
|
||||
beforeEach { clearMocks(messageService) }
|
||||
|
||||
test("@MockkBean stubs and verifies a Spring-managed MockK mock") {
|
||||
every { messageService.getMessage() } returns "hello from @MockkBean"
|
||||
|
||||
messageService.getMessage() shouldBe "hello from @MockkBean"
|
||||
|
||||
verify(exactly = 1) { messageService.getMessage() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.hoennig.gittally.framework
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.testcontainers.containers.GenericContainer
|
||||
import org.testcontainers.utility.DockerImageName
|
||||
|
||||
class TestcontainersSmokeTest : FunSpec({
|
||||
|
||||
test("Testcontainers starts a container") {
|
||||
val container = GenericContainer(DockerImageName.parse("alpine:3"))
|
||||
.withCommand("sh", "-c", "sleep 30")
|
||||
container.start()
|
||||
container.isRunning shouldBe true
|
||||
container.stop()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.hoennig.gittally.framework
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer
|
||||
import com.github.tomakehurst.wiremock.client.WireMock.aResponse
|
||||
import com.github.tomakehurst.wiremock.client.WireMock.get
|
||||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
|
||||
class WireMockSmokeTest : FunSpec({
|
||||
|
||||
val server = WireMockServer(options().dynamicPort())
|
||||
|
||||
beforeSpec { server.start() }
|
||||
afterSpec { server.stop() }
|
||||
|
||||
test("WireMock stubs an HTTP endpoint") {
|
||||
server.stubFor(get("/ping").willReturn(aResponse().withStatus(200).withBody("pong")))
|
||||
|
||||
val response = HttpClient.newHttpClient().send(
|
||||
HttpRequest.newBuilder().uri(URI.create("http://localhost:${server.port()}/ping")).build(),
|
||||
HttpResponse.BodyHandlers.ofString(),
|
||||
)
|
||||
|
||||
response.statusCode() shouldBe 200
|
||||
response.body() shouldBe "pong"
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user