static boolean ok;
@Test
public void testAsyncCallback() throws Exception
{
ResteasyClient client = new ResteasyClientBuilder().build();
{
ok = false;
Future<Response> future = client.target(generateURL("/test")).request().async().get(new InvocationCallback<Response>()
{
@Override
public void completed(Response response)
{
String entity = response.readEntity(String.class);
Assert.assertEquals("get", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
Response res = future.get();
Assert.assertEquals(200, res.getStatus());
Assert.assertTrue(ok);
}
{
ok = false;
Future<String> future = client.target(generateURL("/test")).request().async().get(new InvocationCallback<String>()
{
@Override
public void completed(String entity)
{
Assert.assertEquals("get", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
String entity = future.get();
Assert.assertEquals("get", entity);
Assert.assertTrue(ok);
}
{
ok = false;
Future<Response> future = client.target(generateURL("/test")).request().async().delete(new InvocationCallback<Response>()
{
@Override
public void completed(Response response)
{
String entity = response.readEntity(String.class);
Assert.assertEquals("delete", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
Response res = future.get();
Assert.assertEquals(200, res.getStatus());
Assert.assertTrue(ok);
}
{
ok = false;
Future<String> future = client.target(generateURL("/test")).request().async().delete(new InvocationCallback<String>()
{
@Override
public void completed(String s)
{
Assert.assertEquals("delete", s);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
String entity = future.get();
Assert.assertEquals("delete", entity);
Assert.assertTrue(ok);
}
{
ok = false;
Future<Response> future = client.target(generateURL("/test")).request().async().put(Entity.text("hello"), new InvocationCallback<Response>()
{
@Override
public void completed(Response response)
{
String entity = response.readEntity(String.class);
Assert.assertEquals("put hello", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
Response res = future.get();
Assert.assertEquals(200, res.getStatus());
Assert.assertTrue(ok);
}
{
ok = false;
Future<String> future = client.target(generateURL("/test")).request().async().put(Entity.text("hello"), new InvocationCallback<String>()
{
@Override
public void completed(String s)
{
Assert.assertEquals("put hello", s);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
String entity = future.get();
Assert.assertEquals("put hello", entity);
Assert.assertTrue(ok);
}
{
ok = false;
Future<Response> future = client.target(generateURL("/test")).request().async().post(Entity.text("hello"), new InvocationCallback<Response>()
{
@Override
public void completed(Response response)
{
String entity = response.readEntity(String.class);
Assert.assertEquals("post hello", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
Response res = future.get();
Assert.assertEquals(200, res.getStatus());
Assert.assertTrue(ok);
}
{
ok = false;
Future<String> future = client.target(generateURL("/test")).request().async().post(Entity.text("hello"), new InvocationCallback<String>()
{
@Override
public void completed(String s)
{
Assert.assertEquals("post hello", s);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
String entity = future.get();
Assert.assertEquals("post hello", entity);
Assert.assertTrue(ok);
}
{
ok = false;
Future<Response> future = client.target(generateURL("/test")).request().async().method("PATCH", Entity.text("hello"), new InvocationCallback<Response>()
{
@Override
public void completed(Response response)
{
String entity = response.readEntity(String.class);
Assert.assertEquals("patch hello", entity);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
Response res = future.get();
Assert.assertEquals(200, res.getStatus());
Assert.assertTrue(ok);
}
{
ok = false;
Future<String> future = client.target(generateURL("/test")).request().async().method("PATCH", Entity.text("hello"), new InvocationCallback<String>()
{
@Override
public void completed(String s)
{
Assert.assertEquals("patch hello", s);
ok = true;
}
@Override
public void failed(Throwable error)
{
}
});
String entity = future.get();
Assert.assertEquals("patch hello", entity);
Assert.assertTrue(ok);
}
client.close();
}