cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1460707 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Date Mon, 25 Mar 2013 15:08:35 GMT
Author: sergeyb
Date: Mon Mar 25 15:08:35 2013
New Revision: 1460707

URL: http://svn.apache.org/r1460707
Log:
Merge branch 'jaxrs-responsebuilder-link' of https://github.com/stain/cxf into trunk

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1460707&r1=1460706&r2=1460707&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Mon Mar 25 15:08:35 2013
@@ -257,55 +257,54 @@ public final class ResponseBuilderImpl e
 
     @Override
     public ResponseBuilder allow(String... arg0) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
     public ResponseBuilder allow(Set<String> arg0) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
     public ResponseBuilder encoding(String arg0) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
     public ResponseBuilder entity(Object arg0, Annotation[] arg1) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
-    public ResponseBuilder link(URI arg0, String arg1) {
-        // TODO Auto-generated method stub
-        return null;
+    public ResponseBuilder link(URI href, String rel) {
+        Link.Builder linkBuilder = new LinkBuilderImpl();
+        return links(linkBuilder.uri(href).rel(rel).build());
     }
 
     @Override
-    public ResponseBuilder link(String arg0, String arg1) {
-        // TODO Auto-generated method stub
-        return null;
+    public ResponseBuilder link(String href, String rel) {
+        Link.Builder linkBuilder = new LinkBuilderImpl();
+        return links(linkBuilder.uri(href).rel(rel).build());
     }
 
     @Override
-    public ResponseBuilder links(Link... arg0) {
-        // TODO Auto-generated method stub
-        return null;
+    public ResponseBuilder links(Link... links) {
+        return addHeader(HttpHeaders.LINK, (Object[])links);
     }
 
     @Override
     public ResponseBuilder replaceAll(MultivaluedMap<String, Object> arg0) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
     public ResponseBuilder variants(Variant... arg0) {
-        // TODO Auto-generated method stub
-        return null;
+        // TODO: Implement
+        throw new UnsupportedOperationException("Not implemented");
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1460707&r1=1460706&r2=1460707&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Mon Mar 25 15:08:35 2013
@@ -27,13 +27,13 @@ import java.util.Locale;
 
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Link;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Variant;
 
 import org.apache.cxf.jaxrs.utils.HttpUtils;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -82,6 +82,81 @@ public class ResponseBuilderImplTest ext
     }
     
     @Test
+    public void testLinkStr() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.putSingle("Link", "<http://example.com/page3>;rel=\"next\"");
+        checkBuild(Response.ok().link("http://example.com/page3", "next").build(), 200, null,
m);
+    }
+
+    @Test
+    public void testLinkStrMultiple() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
+        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        checkBuild(Response.ok().link("http://example.com/page1", "previous")
+                       .link("http://example.com/page3", "next").build(), 200, null, m);
+    }
+    
+    @Test
+    public void testLinkStrMultipleSameRel() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", "<http://example.com/page2.pdf>;rel=\"alternate\"");
+        m.add("Link", "<http://example.com/page2.txt>;rel=\"alternate\"");
+        checkBuild(Response.ok().link("http://example.com/page2.pdf", "alternate")
+                       .link("http://example.com/page2.txt", "alternate").build(), 200, null,
m);
+    }
+    
+    @Test
+    public void testLinkURI() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        URI uri = URI.create("http://example.com/page3");
+        m.putSingle("Link", "<http://example.com/page3>;rel=\"next\"");
+        checkBuild(Response.ok().link(uri, "next").build(), 200, null, m);
+    }
+
+    @Test
+    public void testLinks() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
+        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
+        Link.Builder linkBuilder = delegate.createLinkBuilder();
+        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
+        // Reset linkbuilder
+        linkBuilder = delegate.createLinkBuilder();
+        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
+        checkBuild(Response.ok().links(prevLink, nextLink).build(), 200, null, m);
+    }
+
+    @Test
+    public void testLinksNoReset() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
+        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
+        Link.Builder linkBuilder = delegate.createLinkBuilder();
+        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
+        linkBuilder = delegate.createLinkBuilder();
+        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
+        checkBuild(Response.ok().links(prevLink).links(nextLink).build(), 200, null, m);
+    }
+
+    @Test
+    public void testLinksWithReset() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
+        Link.Builder linkBuilder = delegate.createLinkBuilder();
+        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
+        linkBuilder = delegate.createLinkBuilder();
+        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
+        // CHECK: Should .links() do a reset? Undocumented feature; so we'll
+        // test with the awkward <code>(Link[])null</code> instead..
+        // Note: .cookie() has same behavior.
+        checkBuild(Response.ok().links(prevLink).links((Link[])null).links(nextLink).build(),
200, null, m);
+    }
+    
+    @Test
     public void testAddHeader() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         m.putSingle("Content-Language", "en");



Mime
View raw message