cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1460842 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Date Mon, 25 Mar 2013 18:50:05 GMT
Author: sergeyb
Date: Mon Mar 25 18:50:05 2013
New Revision: 1460842

URL: http://svn.apache.org/r1460842
Log:
Merged revisions 1460722,1460724-1460725 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1460722 | sergeyb | 2013-03-25 18:45:44 +0300 (Mon, 25 Mar 2013) | 1 line
  
  Corrected expected/actual order in checkBuild() unit test
........
  r1460724 | sergeyb | 2013-03-25 18:46:43 +0300 (Mon, 25 Mar 2013) | 8 lines
  
  CXF-4914 implemented empty responsebuilder methods
  
  allow(..)
  allow(Set)
  encoding()
  entity(Object, Annotation[])
  replaceAll()
  variants(..)
........
  r1460725 | sergeyb | 2013-03-25 18:47:31 +0300 (Mon, 25 Mar 2013) | 1 line
  
  Keep checkstyle happy by not "hiding" fields
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1460722-1460725

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1460842&r1=1460841&r2=1460842&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Mon Mar 25 18:50:05 2013
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.impl;
 import java.lang.annotation.Annotation;
 import java.net.URI;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
@@ -47,6 +48,7 @@ public final class ResponseBuilderImpl e
     private int status = 200;
     private Object entity;
     private MultivaluedMap<String, Object> metadata = new MetadataMap<String, Object>();
+    private Annotation[] annotations;
 
     public ResponseBuilderImpl() {
     }
@@ -58,10 +60,11 @@ public final class ResponseBuilderImpl e
     }
        
     public Response build() {
-        ResponseImpl r = new ResponseImpl(status, entity);
+        ResponseImpl r = new ResponseImpl(status);
         MetadataMap<String, Object> m = 
             new MetadataMap<String, Object>(metadata, false, true);
         r.addMetadata(m);
+        r.setEntity(entity, annotations);
         reset();
         return r;
     }
@@ -160,7 +163,6 @@ public final class ResponseBuilderImpl e
         type(variant == null ? null : variant.getMediaType());
         language(variant == null ? null : variant.getLanguage());
         setHeader(HttpHeaders.CONTENT_ENCODING, variant == null ? null : variant.getEncoding());
-        
         return this;
     }
 
@@ -220,6 +222,7 @@ public final class ResponseBuilderImpl e
     private void reset() {
         metadata.clear();
         entity = null;
+        annotations = null;
         status = 200;
     }
     
@@ -256,27 +259,25 @@ public final class ResponseBuilderImpl e
     }
 
     @Override
-    public ResponseBuilder allow(String... arg0) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder allow(String... methods) {
+        return addHeader(HttpHeaders.ALLOW, (Object[])methods);
     }
 
     @Override
-    public ResponseBuilder allow(Set<String> arg0) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder allow(Set<String> methods) {
+        return allow(methods.toArray(new String[methods.size()]));
     }
 
     @Override
-    public ResponseBuilder encoding(String arg0) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder encoding(String encoding) {
+        return setHeader(HttpHeaders.CONTENT_ENCODING, encoding);
     }
 
     @Override
-    public ResponseBuilder entity(Object arg0, Annotation[] arg1) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder entity(Object ent, Annotation[] anns) {
+        this.annotations = anns;
+        this.entity = ent;
+        return this;
     }
 
     @Override
@@ -297,14 +298,19 @@ public final class ResponseBuilderImpl e
     }
 
     @Override
-    public ResponseBuilder replaceAll(MultivaluedMap<String, Object> arg0) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder replaceAll(MultivaluedMap<String, Object> map) {
+        metadata.clear();
+        if (map != null) {
+            metadata.putAll(map);
+        }
+        return this;
     }
 
     @Override
-    public ResponseBuilder variants(Variant... arg0) {
-        // TODO: Implement
-        throw new UnsupportedOperationException("Not implemented");
+    public ResponseBuilder variants(Variant... variants) {
+        if (variants == null) {
+            return variants((List<Variant>)null);
+        }
+        return variants(Arrays.asList(variants));
     }
 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1460842&r1=1460841&r2=1460842&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Mon Mar 25 18:50:05 2013
@@ -19,12 +19,16 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.lang.annotation.Annotation;
 import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
 
+import javax.ws.rs.Produces;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Link;
@@ -41,6 +45,76 @@ import org.junit.Test;
 public class ResponseBuilderImplTest extends Assert {
 
     @Test
+    public void testAllow() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Allow", "HEAD");
+        m.add("Allow", "GET");
+        checkBuild(Response.ok().allow("HEAD").allow("GET").build(), 200, null, m);
+    }
+    
+    @Test
+    public void testEncoding() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Content-Encoding", "gzip");
+        checkBuild(Response.ok().encoding("gzip").build(), 200, null, m);
+    }
+
+    @Test
+    public void testEntity() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        checkBuild(Response.ok().entity("Hello").build(), 200, "Hello", m);
+    }
+
+    @Test
+    public void testEntityAnnotations() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        Annotation[] annotations = new Annotation[1];
+        Annotation produces = new Produces() {
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return Produces.class;
+            }
+            @Override
+            public String[] value() {
+                return new String[] {
+                    "text/turtle"
+                };
+            }
+        };
+        annotations[0] = produces;
+        Response response = Response.ok().entity("<> a <#test>", annotations).build();
+        checkBuild(response, 200, "<> a <#test>", m);
+        assertArrayEquals(annotations, ((ResponseImpl)response).getEntityAnnotations());
+    }
+
+    @Test
+    public void testReplaceAll() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Content-Type", "text/plain");
+        checkBuild(Response.ok().type("image/png").tag("removeme").replaceAll(m).build(),
200, null, m);
+
+    }
+
+    @Test
+    public void testAllowReset() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Allow", "POST");
+        checkBuild(Response.ok().allow("HEAD").allow("GET").allow().allow("POST").build(),
200, null, m);
+    }
+
+    @Test
+    public void testAllowSet() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Allow", "HEAD");
+        m.add("Allow", "GET");
+        // LinkedHashSet so we get a predictable order
+        Set<String> methods = new LinkedHashSet<String>();
+        methods.add("HEAD");
+        methods.add("GET");
+        checkBuild(Response.ok().allow(methods).build(), 200, null, m);
+    }
+
+    @Test
     public void testValidStatus() {
         assertEquals(100, Response.status(100).build().getStatus());
         assertEquals(101, Response.status(101).build().getStatus());
@@ -251,15 +325,28 @@ public class ResponseBuilderImplTest ext
     private void checkBuild(Response r, int status, Object entity, 
                             MetadataMap<String, Object> meta) {
         ResponseImpl ri = (ResponseImpl)r;
-        assertEquals("Wrong status", ri.getStatus(), status);
-        assertSame("Wrong entity", ri.getEntity(), entity);
-        assertEquals("Wrong meta", ri.getMetadata(), meta);
+        assertEquals("Wrong status", status, ri.getStatus());
+        assertSame("Wrong entity", entity, ri.getEntity());
+        assertEquals("Wrong meta", meta, ri.getMetadata());
     }
     
     @Test
-    public void testVariants() throws Exception {
+    public void testVariantsArray() throws Exception {
         
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Accept", "application/json");
+        m.add("Accept", "application/xml");
+        m.add("Vary", "Accept");
+
+        Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, (String)null, null);
+        Variant xml = new Variant(MediaType.APPLICATION_XML_TYPE, (String)null, null);
+
+        checkBuild(Response.ok().variants(json, xml).build(), 200, null, m);
+    }
+
+    @Test
+    public void testVariantsList() throws Exception {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         m.add("Accept", "text/xml");
         m.add("Accept", "application/xml");
         m.add("Accept-Language", "en_UK");
@@ -278,5 +365,4 @@ public class ResponseBuilderImplTest ext
                    200, null, m);
     }
     
-    
 }



Mime
View raw message