Skip to content

Commit

Permalink
JAX_RS_SPEC-513 (@patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Apr 21, 2017
1 parent 7622e4c commit fb7e4d2
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,19 @@ public Future<Response> patch(Entity<?> entity) {
@Override
public <T> Future<T> patch(Entity<?> entity, Class<T> responseType)
{
throw new NotImplementedYetException();
return method(HttpMethod.PATCH, entity, responseType);
}

@Override
public <T> Future<T> patch(Entity<?> entity, GenericType<T> responseType)
{
throw new NotImplementedYetException();
return method(HttpMethod.PATCH, entity, responseType);
}

@Override
public <T> Future<T> patch(Entity<?> entity, InvocationCallback<T> callback)
{
throw new NotImplementedYetException();
return method(HttpMethod.PATCH, entity, callback);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,19 @@ public <T extends RxInvoker> T rx(Class<T> clazz)
@Override
public Response patch(Entity<?> entity)
{
throw new NotImplementedYetException();
return build(HttpMethod.PATCH, entity).invoke();
}

@Override
public <T> T patch(Entity<?> entity, Class<T> responseType)
{
throw new NotImplementedYetException();
return build(HttpMethod.PATCH, entity).invoke(responseType);
}

@Override
public <T> T patch(Entity<?> entity, GenericType<T> responseType)
{
throw new NotImplementedYetException();
return build(HttpMethod.PATCH, entity).invoke(responseType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,40 @@ public ExecutorService getExecutor()
@Override
public CompletionStage<Response> patch(Entity<?> entity)
{
throw new NotImplementedYetException();
if (executor == null)
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity));
}
else
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity), executor);
}
}

@Override
public <T> CompletionStage<T> patch(Entity<?> entity, Class<T> responseType)
{
throw new NotImplementedYetException();
if (executor == null)
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity, responseType));
}
else
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity, responseType), executor);
}
}

@Override
public <T> CompletionStage<T> patch(Entity<?> entity, GenericType<T> responseType)
{
throw new NotImplementedYetException();
if (executor == null)
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity, responseType));
}
else
{
return CompletableFuture.supplyAsync(() -> builder.patch(entity, responseType), executor);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.jboss.resteasy.test.client;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.resteasy.test.client.resource.JAXRS21SyncInvokeResource;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.jboss.resteasy.utils.TestUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
@RunAsClient
public class JAXRS21PatchTest extends ClientTestBase {

static Client client;

@Deployment
public static Archive<?> deploy() {
WebArchive war = TestUtil.prepareArchive(JAXRS21PatchTest.class.getSimpleName());
war.addClass(JAXRS21PatchTest.class);
return TestUtil.finishContainerPrepare(war, null, JAXRS21SyncInvokeResource.class);
}

@Before
public void init() {
client = ClientBuilder.newClient();
}

@After
public void after() throws Exception {
client.close();
}

@Test
public void testMethods() throws Exception {
{
Response res = client.target(generateURL("/test")).request().patch(Entity.text("hello"));
Assert.assertEquals(HttpResponseCodes.SC_OK, res.getStatus());
String entity = res.readEntity(String.class);
Assert.assertEquals("patch hello", entity);
}
{
String entity = client.target(generateURL("/test")).request().patch(Entity.text("hello"), String.class);
Assert.assertEquals("patch hello", entity);
}
}

@Test
public void testInvoke() throws Exception {
{
Response res = client.target(generateURL("/test")).request().build(HttpMethod.PATCH, Entity.text("hello")).invoke();
Assert.assertEquals(HttpResponseCodes.SC_OK, res.getStatus());
String entity = res.readEntity(String.class);
Assert.assertEquals("patch hello", entity);
}
{
String entity = client.target(generateURL("/test")).request().build(HttpMethod.PATCH, Entity.text("hello")).invoke(String.class);
Assert.assertEquals("patch hello", entity);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jboss.resteasy.test.client.resource;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/test")
public class JAXRS21SyncInvokeResource {
@GET
@Produces("text/plain")
public String get() {
return "get";
}

@PUT
@Consumes("text/plain")
public String put(String str) {
return "put " + str;
}

@POST
@Consumes("text/plain")
public String post(String str) {
return "post " + str;
}

@DELETE
@Produces("text/plain")
public String delete() {
return "delete";
}

@PATCH
@Produces("text/plain")
@Consumes("text/plain")
public String patch(String str) {
return "patch " + str;
}
}

0 comments on commit fb7e4d2

Please sign in to comment.