diff --git a/webtau-http/src/main/java/org/testingisdocumenting/webtau/http/datanode/DataNode.java b/webtau-http/src/main/java/org/testingisdocumenting/webtau/http/datanode/DataNode.java index e40b5b43b..236031921 100644 --- a/webtau-http/src/main/java/org/testingisdocumenting/webtau/http/datanode/DataNode.java +++ b/webtau-http/src/main/java/org/testingisdocumenting/webtau/http/datanode/DataNode.java @@ -32,7 +32,7 @@ import static org.testingisdocumenting.webtau.WebTauCore.createActualPath; -public interface DataNode extends DataNodeExpectations, BinaryDataProvider, Comparable, Iterable, PrettyPrintable { +public interface DataNode extends DataNodeExpectations, BinaryDataProvider, Comparable, Iterable, PrettyPrintable { DataNodeId id(); DataNode get(String pathOrName); @@ -43,7 +43,7 @@ public interface DataNode extends DataNodeExpectations, BinaryDataProvider, Comp TraceableValue getTraceableValue(); - E get(); + E get(); boolean isList(); @@ -67,7 +67,7 @@ default byte[] getBinaryContent() { throw new IllegalArgumentException("datanode is not binary"); } - return get(); + return (byte[]) get(); } @Override diff --git a/webtau-junit5-examples/pom.xml b/webtau-junit5-examples/pom.xml index 258775689..839928f33 100644 --- a/webtau-junit5-examples/pom.xml +++ b/webtau-junit5-examples/pom.xml @@ -29,7 +29,7 @@ true - 1.3.70 + 1.8.0 @@ -229,6 +229,9 @@ + + 1.4 + diff --git a/webtau-junit5-examples/src/test/java/com/example/tests/junit5/CustomerCrudJavaTest.java b/webtau-junit5-examples/src/test/java/com/example/tests/junit5/CustomerCrudJavaTest.java index bba33729e..6f6fe8c45 100644 --- a/webtau-junit5-examples/src/test/java/com/example/tests/junit5/CustomerCrudJavaTest.java +++ b/webtau-junit5-examples/src/test/java/com/example/tests/junit5/CustomerCrudJavaTest.java @@ -27,10 +27,10 @@ public void crud() { "firstName", "FN", "lastName", "NLN"); - http.put("/customers/" + id, changedCustomerPayload, ((header, body) -> { - body.get("firstName").should(equal("FN")); - body.get("lastName").should(equal(changedLastName)); - })); +http.put("/customers/" + id, changedCustomerPayload, ((header, body) -> { + body.get("firstName").should(equal("FN")); + body.get("lastName").should(equal(changedLastName)); +})); http.get("/customers/" + id, ((header, body) -> { body.should(equal(changedCustomerPayload)); diff --git a/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/HttpKotlin.kt b/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/HttpKotlin.kt new file mode 100644 index 000000000..6b99508b4 --- /dev/null +++ b/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/HttpKotlin.kt @@ -0,0 +1,93 @@ +/* + * Copyright 2023 webtau maintainers + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.kotlin.http + +import org.testingisdocumenting.webtau.data.Data +import org.testingisdocumenting.webtau.http.Http +import org.testingisdocumenting.webtau.http.datanode.DataNode +import org.testingisdocumenting.webtau.http.validation.HeaderDataNode +import org.testingisdocumenting.webtau.http.validation.HttpResponseValidator +import org.testingisdocumenting.webtau.http.validation.HttpResponseValidatorWithReturn + +val http = HttpKotlin() + +fun interface KotlinValidator { + fun validate() +} + +fun interface KotlinValidatorWithReturn { + fun validateAndReturn(): Any +} + +fun interface HttpKotlinResponseValidator { + fun validate(header: HeaderDataNode, body: DataNode): Any +} + +//fun client(validator: KotlinValidator) { +// println("validator NO return") +// validator.validate() +//} + +//fun client(validatorAndReturn: KotlinValidatorWithReturn): E { +// println("validator WITH return") +// return validatorAndReturn.validateAndReturn() +//} + +fun test() { +// val fromValidator = client { +// 100 +// } +// +// val fromValidatorForced = client(KotlinValidatorWithReturn { +// 100 +// }) +// +// client { +// } +} + + +//fun interface KotlinValidator { +// fun validate(header: HeaderDataNode, body: DataNode) +//} +// +//fun interface KotlinValidatorWithReturn { +// fun validateAndReturn(header: HeaderDataNode, body: DataNode): Any +//} + +class HttpKotlin { + fun post(url: String, payload: Map, validator: HttpResponseValidatorWithReturn): Any { + println("kotlin post return") + return Http.http.post(url, payload, validator) + } + + fun post(url: String, payload: Map, validator: KotlinValidator) { + println("kotlin post") + post(url, payload, validator) + } + +// fun post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Any): R { +// println("kotlin post return") +// return post(url, payload, HttpResponseValidatorWithReturn(validator)) +// } + +// fun post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Unit) { +// println("kotlin post") +// post(url, payload, HttpResponseValidator(validator)) +// } +} + diff --git a/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/WebTauKotlinDsl.kt b/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/WebTauKotlinDsl.kt new file mode 100644 index 000000000..0f84d1a8b --- /dev/null +++ b/webtau-junit5-examples/src/test/kotlin/com/example/kotlin/http/WebTauKotlinDsl.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2023 webtau maintainers + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.kotlin.http + +import org.testingisdocumenting.webtau.http.Http +import org.testingisdocumenting.webtau.http.datanode.DataNode +import org.testingisdocumenting.webtau.http.validation.HeaderDataNode +import org.testingisdocumenting.webtau.http.validation.HttpResponseValidator +import org.testingisdocumenting.webtau.http.validation.HttpResponseValidatorWithReturn + +//private val http: Http = Http.http + +//fun Http.post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Any): R { +// println("kotlin post return") +// return Http.http.post(url, payload, HttpResponseValidatorWithReturn(validator)) +//} +// +//fun Http.post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Unit) { +// println("kotlin post") +// Http.http.post(url, payload, HttpResponseValidator(validator)) +//} +// +//fun Http.todo() { +// println("todo extension external") +//} + + +//class WebTauKotlinDsl : WebTauDsl() { +// +// fun Http.todoInternal() { +// println("todo extension") +// } +// +// fun Http.post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Any): R { +// println("kotlin post return") +// return http.post(url, payload, HttpResponseValidatorWithReturn(validator)) +// } +// +// fun Http.post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Unit) { +// println("kotlin post") +// http.post(url, payload, HttpResponseValidator(validator)) +// } +//} \ No newline at end of file diff --git a/webtau-junit5-examples/src/test/kotlin/com/example/tests/junit5/CustomerCrudSeparatedKotlinTest.kt b/webtau-junit5-examples/src/test/kotlin/com/example/tests/junit5/CustomerCrudSeparatedKotlinTest.kt index 58be94300..f3ad700f4 100644 --- a/webtau-junit5-examples/src/test/kotlin/com/example/tests/junit5/CustomerCrudSeparatedKotlinTest.kt +++ b/webtau-junit5-examples/src/test/kotlin/com/example/tests/junit5/CustomerCrudSeparatedKotlinTest.kt @@ -1,63 +1,89 @@ package com.example.tests.junit5 -import org.testingisdocumenting.webtau.WebTauDsl.* -import org.testingisdocumenting.webtau.http.validation.HttpResponseValidatorWithReturn +//import com.example.kotlin.http.WebTauKotlinDsl.* +import com.example.kotlin.http.test +//import org.testingisdocumenting.webtau.WebTauDsl.* import org.testingisdocumenting.webtau.junit5.WebTau +import com.example.kotlin.http.* + import org.junit.jupiter.api.* @WebTau @TestMethodOrder(MethodOrderer.OrderAnnotation::class) @DisplayName("customer") class CustomerCrudSeparatedKotlinTest { - @Test - @Order(1) - fun `read customer record`() { - http.get("/customers/$id") { _, body -> - body.should(equal(customerPayload)) - } - } - - @Test - @Order(2) - fun `update customer record`() { - http.put("/customers/$id", changedCustomerPayload) { _, body -> - body.should(equal(changedCustomerPayload)) - } - - http.get("/customers/$id") { _, body -> - body.should(equal(changedCustomerPayload)) - } - } - - @Test - @Order(3) - fun `delete customer`() { - http.delete("/customers/$id") { header, _ -> - header.statusCode().should(equal(204)) - } - - http.get("/customers/$id") { header, _ -> - header.statusCode().should(equal(404)) - } - } - companion object { private val customerPayload = mapOf( "firstName" to "FN", "lastName" to "LN" ) + private val changedCustomerPayload = mapOf( "lastName" to "NLN" ) - private val id by lazy { - val id: Int = http.post("/customers", customerPayload, HttpResponseValidatorWithReturn { _, body -> - body.get("id") - }) - actual(id).shouldNot(equal(0)) + private var id: Int = 0 + } + +// private fun post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Any): R { +// return http.post(url, payload, HttpResponseValidatorWithReturn(validator)) +// } +// +// private fun post(url: String, payload: Map, validator: (header: HeaderDataNode, body: DataNode) -> Unit) { +// http.post(url, payload, HttpResponseValidator(validator)) +// } - id + @Test + fun testValidators() { + test() + } + + @Test + @Order(1) + fun `create customer`() { + id = http.post("/customers", customerPayload) { _, body -> + body.get("id") + } as Int + + http.post("/customers", customerPayload) { _, body -> + body.get("id") } +// +// http.post("/customers", customerPayload) { _, body -> +// +// } } + +// @Test +// @Order(2) +// fun `read customer`() { +// http.get("/customers/$id") { _, body -> +// body.should(equal(customerPayload)) +// } +// } +// +// @Test +// @Order(3) +// fun `update customer`() { +// http.put("/customers/$id", changedCustomerPayload) { _, body -> +// body.should(equal(changedCustomerPayload)) +// } +// +// http.get("/customers/$id") { _, body -> +// body.should(equal(changedCustomerPayload)) +// } +// } +// +// @Test +// @Order(4) +// fun `delete customer`() { +// http.delete("/customers/$id") { header, _ -> +// header.statusCode.should(equal(204)) +// } +// +// http.get("/customers/$id") { header, _ -> +// header.statusCode.should(equal(404)) +// } +// } }