cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6793] Adding a test
Date Mon, 22 Feb 2016 14:09:11 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 74d026096 -> 0c1f1e6a9


[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/0c1f1e6a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0c1f1e6a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0c1f1e6a

Branch: refs/heads/3.1.x-fixes
Commit: 0c1f1e6a9b7d0510783f602ff608c9f1390d64b8
Parents: 74d0260
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Feb 22 14:07:43 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Feb 22 14:08:57 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/0c1f1e6a/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/0c1f1e6a/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/0c1f1e6a/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;
+        }
+
+        
+    }
 }


Mime
View raw message