Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for #8 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
{

Expand Down Expand Up @@ -41,7 +43,25 @@ 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();
}

@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();
}
}
20 changes: 20 additions & 0 deletions src/test/java/org/tynamo/resteasy/ws/ReloadableEchoResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -18,4 +21,21 @@ 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<Long> params);

class GenericLongsRequest
{
public List<Long> params;
}

@POST
@Path("/generic_longs_workaround")
@Consumes("application/json")
@Produces("application/json")
Response genericLongsWorkaround(GenericLongsRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -13,4 +14,18 @@ public Response echo(String message)
return Response.status(200).entity(new JSONObject("message", message).toCompactString()).build();
}

@Override
public Response genericLongs(List<Long> params)
{
Long first = params.get(0); // java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
return Response.ok(first).build();
}

@Override
public Response genericLongsWorkaround(GenericLongsRequest request)
{
Long first = request.params.get(0); // OK
return Response.ok(first).build();
}

}