diff --git a/build.gradle b/build.gradle index cecc34d67..d201fae67 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ subprojects { group = 'org.httprpc' - version = '4.4.2' + version = '4.4.3' apply plugin: 'java-library' diff --git a/kilo-test/src/main/java/org/httprpc/kilo/test/TestService.java b/kilo-test/src/main/java/org/httprpc/kilo/test/TestService.java index c45515764..563a07a68 100644 --- a/kilo-test/src/main/java/org/httprpc/kilo/test/TestService.java +++ b/kilo-test/src/main/java/org/httprpc/kilo/test/TestService.java @@ -14,6 +14,7 @@ package org.httprpc.kilo.test; +import jakarta.servlet.ServletException; import jakarta.servlet.annotation.MultipartConfig; import jakarta.servlet.annotation.WebServlet; import org.httprpc.kilo.Creates; @@ -302,9 +303,28 @@ public Coordinates testPostCoordinates(Coordinates coordinates) { @RequestMethod("POST") @ResourcePath("form-data") - public Map testPostFormData(Void body) { - // TODO Read parts - return null; + public Map testPostFormData(Void body) throws IOException, ServletException { + String string = null; + List strings = null; + Integer number = null; + Set numbers = null; + + var fileSize = 0; + var totalFileSize = 0; + + for (var part : getRequest().getParts()) { + // TODO + var name = part.getName(); + } + + return mapOf( + entry("string", string), + entry("strings", strings), + entry("number", number), + entry("numbers", numbers), + entry("fileSize", fileSize), + entry("totalFileSize", totalFileSize) + ); } @RequestMethod("POST") diff --git a/kilo-test/src/test/java/org/httprpc/kilo/test/TestServiceProxy.java b/kilo-test/src/test/java/org/httprpc/kilo/test/TestServiceProxy.java index 6b3f639e3..faa93b48c 100644 --- a/kilo-test/src/test/java/org/httprpc/kilo/test/TestServiceProxy.java +++ b/kilo-test/src/test/java/org/httprpc/kilo/test/TestServiceProxy.java @@ -37,8 +37,10 @@ @ServicePath("test") public interface TestServiceProxy { interface FormData { + @Required String getString(); - List getNumbers(); + List getStrings(); + Integer getNumber(); Date getDate(); Path getFile(); List getFiles(); diff --git a/kilo-test/src/test/java/org/httprpc/kilo/test/WebServiceProxyTest.java b/kilo-test/src/test/java/org/httprpc/kilo/test/WebServiceProxyTest.java index b3267faaf..4784a7793 100644 --- a/kilo-test/src/test/java/org/httprpc/kilo/test/WebServiceProxyTest.java +++ b/kilo-test/src/test/java/org/httprpc/kilo/test/WebServiceProxyTest.java @@ -36,6 +36,7 @@ import java.time.Period; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.UUID; import static org.httprpc.kilo.util.Collections.*; @@ -365,44 +366,61 @@ public void testCoordinatesPost() throws IOException { @Test public void testFormDataPost() throws IOException { + var now = new Date(); + var textURL = getClass().getResource("test.txt"); var imageURL = getClass().getResource("test.jpg"); var body = mapOf( - entry("string", "abc"), - entry("numbers", listOf(1, 2, 3)), - entry("date", new Date()), + entry("string", "héllo&gøod+bye?"), + entry("strings", listOf("a", "b", "c")), + entry("number", 123), + entry("date", now), entry("file", textURL.getPath()), entry("files", listOf(textURL.getPath(), imageURL.getPath())) ); var webServiceProxy = new WebServiceProxy("POST", baseURI.resolve("test/form-data")); + webServiceProxy.setRequestHandler(new WebServiceProxy.FormDataRequestHandler()); webServiceProxy.setBody(body); - var result = webServiceProxy.invoke(); + var result = (Map)webServiceProxy.invoke(); - // TODO + assertEquals(result.get("string"), "héllo&gøod+bye?"); + assertEquals(result.get("strings"), listOf("a", "b", "c")); + assertEquals(result.get("number"), 123); + assertEquals(result.get("date"), now.getTime()); + assertEquals(result.get("fileSize"), 0); + assertEquals(result.get("totalFileSize"), 0); } @Test public void testFormDataPostProxy() throws IOException { var testServiceProxy = WebServiceProxy.of(TestServiceProxy.class, baseURI); + var now = new Date(); + var textURL = getClass().getResource("test.txt"); var imageURL = getClass().getResource("test.jpg"); var formData = BeanAdapter.coerce(mapOf( - entry("string", "abc"), - entry("numbers", listOf(1, 2, 3)), - entry("date", new Date()), + entry("string", "héllo&gøod+bye?"), + entry("strings", listOf("a", "b", "c")), + entry("number", 123), + entry("date", now), entry("file", textURL.getPath()), entry("files", listOf(textURL.getPath(), imageURL.getPath())) ), TestServiceProxy.FormData.class); var result = testServiceProxy.testFormDataPost(formData); - // TODO + assertEquals(result.get("string"), "héllo&gøod+bye?"); + assertEquals(result.get("strings"), listOf("a", "b", "c")); + assertEquals(result.get("number"), 123); + assertEquals(result.get("date"), now.getTime()); + assertEquals(result.get("fileSize"), 0); + assertEquals(result.get("totalFileSize"), 0); } @Test