From 820e22e88b9219576864cdc4d6d357ee6d77b22d Mon Sep 17 00:00:00 2001 From: Tim Ysewyn Date: Fri, 18 Jun 2021 15:40:59 +0200 Subject: [PATCH] Wrong type for delay in Kotlin spec; fixes gh-1668 --- .../contract/spec/internal/ResponseDsl.kt | 7 +++- .../cloud/contract/spec/ContractTests.kt | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt index b74c043ef1..a22341db2d 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt @@ -69,7 +69,12 @@ class ResponseDsl : CommonDsl() { fun code(code: Int): DslProperty = code.toDslProperty() - fun fixedMilliseconds(delay: Long): DslProperty = delay.toDslProperty() + fun fixedMilliseconds(delay: Int): DslProperty = delay.toDslProperty() + + /** + * @deprecated Use the {@link #fixedMilliseconds(int) fixedMilliseconds} method. + */ + fun fixedMilliseconds(delay: Long): DslProperty = fixedMilliseconds(delay.toInt()) fun headers(headers: HeadersDsl.() -> Unit) { this.headers = ResponseHeadersDsl().apply(headers).get() diff --git a/specs/spring-cloud-contract-spec-kotlin/src/test/kotlin/org/springframework/cloud/contract/spec/ContractTests.kt b/specs/spring-cloud-contract-spec-kotlin/src/test/kotlin/org/springframework/cloud/contract/spec/ContractTests.kt index 70ea5c6429..ef1d533595 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/test/kotlin/org/springframework/cloud/contract/spec/ContractTests.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/test/kotlin/org/springframework/cloud/contract/spec/ContractTests.kt @@ -804,4 +804,42 @@ then: } } + @Test + /** + * See issue https://github.com/spring-cloud/spring-cloud-contract/issues/1668 + */ + fun `should convert delay from long to int`() { + val contract = contract { + name = "Test Controller" + description = "Some description" + request { + method = GET + url = url("/credentials") withQueryParameters { + parameter("type", "foo") + } + } + response { + delay = fixedMilliseconds(1000L) + status = OK + body = body( + listOf( + mapOf( + "type" to "test1" + ) + ) + ) + } + } + + assertDoesNotThrow { + Contract.assertContract(contract) + }.also { + val response = contract.response + assertThat(response.delay.clientValue).isInstanceOf(java.lang.Integer::class.java) + assertThat(response.delay.clientValue).isEqualTo(1000) + assertThat(response.delay.serverValue).isInstanceOf(java.lang.Integer::class.java) + assertThat(response.delay.serverValue).isEqualTo(1000) + } + } + } \ No newline at end of file