From c80033673b0a4e749775060e7c4e8391e02c2f5f Mon Sep 17 00:00:00 2001 From: Dmitry Gusev Date: Sat, 1 Apr 2017 14:42:55 +0300 Subject: [PATCH 1/2] Test for #8 --- .../integration/ResteasyIntegrationTest.java | 18 ++++++++++++++---- .../resteasy/ws/ReloadableEchoResource.java | 9 +++++++++ .../ws/ReloadableEchoResourceImpl.java | 8 ++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java b/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java index 726a1a6..3c7c145 100644 --- a/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java +++ b/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java @@ -1,14 +1,16 @@ package org.tynamo.resteasy.integration; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.ClientBuilder; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tynamo.test.AbstractContainerTest; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; + public class ResteasyIntegrationTest extends AbstractContainerTest { @@ -41,7 +43,15 @@ public void testEchoResource() throws Exception String response = builder.get(String.class); Assert.assertEquals(response, "{\"message\":\"Hellow World!\"}"); client.close(); - } + @Test + public void testEchoGenericListOfLongs() throws Exception + { + Client client = ClientBuilder.newClient(); + Invocation.Builder builder = client.target(BASEURI + "mycustomresteasyprefix/echo/generic_longs").request(); + String response = builder.post(Entity.json("[1, 2, 3]"), String.class); + Assert.assertEquals(response, "1"); + client.close(); + } } diff --git a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java index e447533..6828eba 100644 --- a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java +++ b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java @@ -3,11 +3,14 @@ import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.util.List; @Api(value = "/echo", description = "the ECHO api") @Path("/echo") @@ -18,4 +21,10 @@ public interface ReloadableEchoResource @Produces("application/json") @ApiOperation("echoes a message") Response echo(@PathParam("message") String message); + + @POST + @Path("/generic_longs") + @Consumes("application/json") + @Produces("application/json") + Response genericLongs(List params); } diff --git a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java index 3848643..40d02fc 100644 --- a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java +++ b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java @@ -3,6 +3,7 @@ import org.apache.tapestry5.json.JSONObject; import javax.ws.rs.core.Response; +import java.util.List; public class ReloadableEchoResourceImpl implements ReloadableEchoResource { @@ -13,4 +14,11 @@ public Response echo(String message) return Response.status(200).entity(new JSONObject("message", message).toCompactString()).build(); } + @Override + public Response genericLongs(List params) + { + Long first = params.get(0); // java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long + return Response.ok(first).build(); + } + } \ No newline at end of file From 60eee1cb1c5a5c3287fa6a2ee267cb13fe0fdf69 Mon Sep 17 00:00:00 2001 From: Dmitry Gusev Date: Sat, 1 Apr 2017 14:56:13 +0300 Subject: [PATCH 2/2] Workaround for #8 --- .../resteasy/integration/ResteasyIntegrationTest.java | 10 ++++++++++ .../tynamo/resteasy/ws/ReloadableEchoResource.java | 11 +++++++++++ .../resteasy/ws/ReloadableEchoResourceImpl.java | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java b/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java index 3c7c145..2c4a10b 100644 --- a/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java +++ b/src/test/java/org/tynamo/resteasy/integration/ResteasyIntegrationTest.java @@ -54,4 +54,14 @@ public void testEchoGenericListOfLongs() throws Exception Assert.assertEquals(response, "1"); client.close(); } + + @Test + public void testEchoGenericListOfLongsWorkaround() throws Exception + { + Client client = ClientBuilder.newClient(); + Invocation.Builder builder = client.target(BASEURI + "mycustomresteasyprefix/echo/generic_longs_workaround").request(); + String response = builder.post(Entity.json("{\"params\": [1, 2, 3]}"), String.class); + Assert.assertEquals(response, "1"); + client.close(); + } } diff --git a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java index 6828eba..789ba32 100644 --- a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java +++ b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java @@ -27,4 +27,15 @@ public interface ReloadableEchoResource @Consumes("application/json") @Produces("application/json") Response genericLongs(List params); + + class GenericLongsRequest + { + public List params; + } + + @POST + @Path("/generic_longs_workaround") + @Consumes("application/json") + @Produces("application/json") + Response genericLongsWorkaround(GenericLongsRequest request); } diff --git a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java index 40d02fc..343c869 100644 --- a/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java +++ b/src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResourceImpl.java @@ -21,4 +21,11 @@ public Response genericLongs(List params) return Response.ok(first).build(); } + @Override + public Response genericLongsWorkaround(GenericLongsRequest request) + { + Long first = request.params.get(0); // OK + return Response.ok(first).build(); + } + } \ No newline at end of file