You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/02/22 15:07:57 UTC
cxf git commit: [CXF-6793] Adding a test
Repository: cxf
Updated Branches:
refs/heads/master 04ce396b6 -> 2a176a5ad
[CXF-6793] Adding a test
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/2a176a5a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/2a176a5a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/2a176a5a
Branch: refs/heads/master
Commit: 2a176a5ada62a935d60c432119fd6da6d89ac77b
Parents: 04ce396
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Mon Feb 22 14:07:43 2016 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Mon Feb 22 14:07:43 2016 +0000
----------------------------------------------------------------------
.../systest/jaxrs/BookServerAsyncClient.java | 58 +++++++++++++++++++-
.../org/apache/cxf/systest/jaxrs/BookStore.java | 2 +-
.../cxf/systest/jaxrs/JAXRSAsyncClientTest.java | 36 ++++++++++++
3 files changed, 94 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/2a176a5a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
index f3d7b62..71ba304 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
@@ -19,8 +19,23 @@
package org.apache.cxf.systest.jaxrs;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -39,7 +54,7 @@ public class BookServerAsyncClient extends AbstractBusTestServerBase {
sf.setResourceProvider(BookStore.class,
new SingletonResourceProvider(new BookStore(), true));
sf.setAddress("http://localhost:" + PORT + "/");
-
+ sf.setProvider(new BooleanReaderWriter());
sf.getProperties(true).put("default.content.type", "*/*");
server = sf.create();
BusFactory.setDefaultBus(null);
@@ -63,4 +78,45 @@ public class BookServerAsyncClient extends AbstractBusTestServerBase {
System.out.println("done!");
}
}
+
+ @Consumes("text/boolean")
+ @Produces("text/boolean")
+ public static class BooleanReaderWriter implements
+ MessageBodyReader<Object>, MessageBodyWriter<Boolean> {
+
+ @Override
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return true;
+ }
+
+ @Override
+ public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3,
+ MultivaluedMap<String, String> arg4, InputStream is) throws IOException,
+ WebApplicationException {
+ return Boolean.valueOf(IOUtils.readStringFromStream(is));
+ }
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType) {
+ return true;
+ }
+
+ @Override
+ public long getSize(Boolean t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(Boolean t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
+ OutputStream os) throws IOException, WebApplicationException {
+ byte[] bytes = t.toString().getBytes("UTF-8");
+ os.write(bytes);
+
+ }
+
+
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/2a176a5a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 4192ee1..665c950 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -540,7 +540,7 @@ public class BookStore {
@GET
@Path("books/check/{id}")
- @Produces("text/plain")
+ @Produces("text/plain,text/boolean")
public boolean checkBook(@PathParam("id") Long id) {
return books.containsKey(id);
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/2a176a5a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
index 8ee9c9c..32e6468 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
@@ -253,6 +253,22 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase {
}
@Test
+ public void testGenericInvocationCallback() throws Exception {
+ InvocationCallback<?> callback = createGenericInvocationCallback();
+ String address = "http://localhost:" + PORT + "/bookstore/books/check/123";
+ Future<?> f = ClientBuilder.newBuilder().register(new BookServerAsyncClient.BooleanReaderWriter())
+ .build().target(address)
+ .request().accept("text/boolean").async().get(callback);
+ Object o = f.get();
+ assertTrue((Boolean)o);
+ assertTrue(((GenericInvocationCallback)callback).getResult());
+ }
+
+ private InvocationCallback<?> createGenericInvocationCallback() {
+ return new GenericInvocationCallback();
+ }
+
+ @Test
public void testGetBookAsync404Callback() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
WebClient wc = createWebClient(address);
@@ -324,6 +340,7 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase {
}
+
public static class TestResponseFilter implements ClientResponseFilter {
@Override
@@ -334,4 +351,23 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase {
}
}
+ private static class GenericInvocationCallback implements InvocationCallback<Object> {
+ private Object result;
+
+ @Override
+ public void completed(final Object o) {
+ result = o;
+ }
+
+ @Override
+ public void failed(final Throwable throwable) {
+ // complete
+ }
+
+ public Boolean getResult() {
+ return (Boolean)result;
+ }
+
+
+ }
}