cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r705546 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 17 Oct 2008 10:21:13 GMT
Author: sergeyb
Date: Fri Oct 17 03:21:11 2008
New Revision: 705546

URL: http://svn.apache.org/viewvc?rev=705546&view=rev
Log:
JAX-RS : updating primitive text provider to support Boolean

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=705546&r1=705545&r2=705546&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
Fri Oct 17 03:21:11 2008
@@ -40,14 +40,16 @@
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
 
     private static boolean isSupported(Class<?> type) { 
-        return type.isPrimitive() || Number.class.isAssignableFrom(type);
+        return type.isPrimitive() 
+            || Number.class.isAssignableFrom(type)
+            || Boolean.class.isAssignableFrom(type);
     }
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations)
{
         return isSupported(type);
     }
 
-    public Object readFrom(Class type, Type genType, Annotation[] anns, MediaType mt, 
+    public Object readFrom(Class<Object> type, Type genType, Annotation[] anns, MediaType
mt, 
                            MultivaluedMap headers, InputStream is) throws IOException {
         return InjectionUtils.handleParameter(
                     IOUtils.readStringFromStream(is).toString(), type);
@@ -57,11 +59,11 @@
         return -1;
     }
 
-    public boolean isWriteable(Class type, Type genericType, Annotation[] annotations) {
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations)
{
         return isSupported(type);
     }
 
-    public void writeTo(Object obj, Class type, Type genType, Annotation[] anns, 
+    public void writeTo(Object obj, Class<?> type, Type genType, Annotation[] anns,

                         MediaType mt, MultivaluedMap headers, OutputStream os) throws IOException
{
         os.write(obj.toString().getBytes("UTF-8"));
     }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java?rev=705546&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
Fri Oct 17 03:21:11 2008
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrimitiveTextProviderTest extends Assert {
+    
+    @Test
+    public void testIsWriteable() {
+        MessageBodyWriter<Object> p = new PrimitiveTextProvider();
+        assertTrue(p.isWriteable(byte.class, null, null)
+                   && p.isWriteable(Byte.class, null, null)
+                   && p.isWriteable(boolean.class, null, null)
+                   && p.isWriteable(Boolean.class, null, null));
+    }
+    
+    @Test
+    public void testIsReadable() {
+        MessageBodyReader<Object> p = new PrimitiveTextProvider();
+        assertTrue(p.isReadable(byte.class, null, null)
+                   && p.isReadable(Byte.class, null, null)
+                   && p.isReadable(boolean.class, null, null)
+                   && p.isReadable(Boolean.class, null, null));
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadByte() throws Exception {
+        MessageBodyReader p = new PrimitiveTextProvider();
+        
+        byte valueRead = (Byte)p.readFrom((Class)byte.class, 
+                                          null, 
+                                          null, 
+                                          null, 
+                                          null, 
+                                          new ByteArrayInputStream("1".getBytes()));
+        assertEquals(1, valueRead);
+        
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadBoolean() throws Exception {
+        MessageBodyReader p = new PrimitiveTextProvider();
+        
+        boolean valueRead = (Boolean)p.readFrom((Class)boolean.class, 
+                                          null, 
+                                          null, 
+                                          null, 
+                                          null, 
+                                          new ByteArrayInputStream("true".getBytes()));
+        assertTrue(valueRead);
+        
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testWriteBoolean() throws Exception {
+        MessageBodyWriter p = new PrimitiveTextProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        p.writeTo(Boolean.TRUE, null, null, null, null, null, os);
+        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
+        
+        os = new ByteArrayOutputStream();
+        
+        final boolean value = true;
+        p.writeTo(value, null, null, null, null, null, os);
+        assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=705546&r1=705545&r2=705546&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Fri Oct 17
03:21:11 2008
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 
+import java.net.URL;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
@@ -70,12 +71,27 @@
         throw new WebApplicationException(response);
     }
     
+    @GET
+    @Path("books/check/{id}")
+    @ProduceMime("text/plain")
+    public boolean checkBook(@PathParam("id") Long id) {
+        return books.containsKey(id);
+    }
+    
     
     @GET
     @Path("timetable")
     public Calendar getTimetable() {
         return new GregorianCalendar();
     }
+    
+    @GET
+    @Path("/bookurl/{URL}/")
+    public Book getBookByURL(@PathParam("URL") String urlValue) throws Exception {
+        String url2 = new URL(urlValue).toString();
+        int index = url2.lastIndexOf('/');
+        return doGetBook(url2.substring(index + 1));
+    } 
 
     @GET
     @Path("/books/{bookId}/")

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=705546&r1=705545&r2=705546&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Oct 17 03:21:11 2008
@@ -34,6 +34,7 @@
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
@@ -41,7 +42,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
     }
     
     @Test
@@ -52,6 +53,15 @@
     }
     
     @Test
+    @Ignore
+    public void testGetBookByURL() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/bookurl/http%3A%2F%2Ftest.com%2Frss%2F123",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+    }
+    
+    
+    @Test
     public void testNoRootResourceException() throws Exception {
         getAndCompare("http://localhost:9080/nobookstore/webappexception",
                       "",
@@ -140,6 +150,34 @@
     }
     
     @Test
+    public void testBookExists() throws Exception {
+        checkBook("http://localhost:9080/bookstore/books/check/123", true);
+        checkBook("http://localhost:9080/bookstore/books/check/124", false);  
+        
+    }
+    
+    private void checkBook(String address, boolean expected) throws Exception {
+        GetMethod get = new GetMethod(address);
+        get.setRequestHeader("Accept", "text/plain");
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(get);
+            assertEquals(200, result);
+            if (expected) {
+                assertEquals("Book must be available",
+                             "true", get.getResponseBodyAsString());
+            } else {
+                assertEquals("Book must not be available",
+                             "false", get.getResponseBodyAsString());
+            }
+        } finally {
+            // Release current connection to the connection pool once you are done
+            get.releaseConnection();
+        }
+    }
+    
+    @Test
     public void testGetBook123() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
                                "resources/expected_get_book123.txt",



Mime
View raw message