cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1479952 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
Date Tue, 07 May 2013 15:52:34 GMT
Author: sergeyb
Date: Tue May  7 15:52:34 2013
New Revision: 1479952

URL: http://svn.apache.org/r1479952
Log:
Custom ResourceComparators can extend OperationResourceInfoComparator so the old constructor
needs to be restored

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=1479952&r1=1479951&r2=1479952&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
Tue May  7 15:52:34 2013
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
@@ -36,14 +37,10 @@ public class OperationResourceInfoCompar
     private boolean getMethod;
     private Message message;
     private ResourceComparator rc;  
-    private MediaType contentType;
-    private List<MediaType> acceptTypes;
+    private MediaType contentType = MediaType.WILDCARD_TYPE;
+    private List<MediaType> acceptTypes = Collections.singletonList(MediaType.WILDCARD_TYPE);
 
-    public OperationResourceInfoComparator(Message m, 
-                                           String httpMethod,
-                                           boolean getMethod,
-                                           MediaType contentType,
-                                           List<MediaType> acceptTypes) {
+    public OperationResourceInfoComparator(Message m, String method) {
         this.message = m;
         if (message != null) {
             Object o = m.getExchange().get(Endpoint.class).get("org.apache.cxf.jaxrs.comparator");
@@ -51,9 +48,17 @@ public class OperationResourceInfoCompar
                 rc = (ResourceComparator)o;
             }
         }
+        this.httpMethod = method;
+    }
+    
+    public OperationResourceInfoComparator(Message m, 
+                                           String httpMethod,
+                                           boolean getMethod,
+                                           MediaType contentType,
+                                           List<MediaType> acceptTypes) {
+        this(m, httpMethod);
         this.contentType = contentType;
         this.acceptTypes = acceptTypes;
-        this.httpMethod = httpMethod;
         this.getMethod = getMethod;
     }
     
@@ -85,7 +90,6 @@ public class OperationResourceInfoCompar
         }
         
         if (result == 0 && !getMethod) {
-        
             result = JAXRSUtils.compareSortedConsumesMediaTypes(
                           e1.getConsumeTypes(), 
                           e2.getConsumeTypes(),

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java?rev=1479952&r1=1479951&r2=1479952&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/OperationResourceInfoTest.java
Tue May  7 15:52:34 2013
@@ -19,12 +19,20 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.EasyMock;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -85,4 +93,60 @@ public class OperationResourceInfoTest e
                      "text/xml", ctypes.get(0).toString());
     }
 
+    @Test
+    public void testComparator1() throws Exception {
+        OperationResourceInfo ori1 = new OperationResourceInfo(
+                                                               TestClass.class.getMethod("doIt",
new Class[]{}), 
+                                                               new ClassResourceInfo(TestClass.class));
+        ori1.setURITemplate(new URITemplate("/"));
+        
+        OperationResourceInfo ori2 = new OperationResourceInfo(
+                                                               TestClass.class.getMethod("doThat",
new Class[]{}), 
+                                                               new ClassResourceInfo(TestClass.class));
+        
+        ori2.setURITemplate(new URITemplate("/"));
+        
+        OperationResourceInfoComparator cmp = new OperationResourceInfoComparator(null, null);
+        
+        
+        int result = cmp.compare(ori1,  ori2);
+        assertEquals(0, result);
+    }
+    
+    @Test
+    public void testComparator2() throws Exception {
+        Message m = createMessage();
+        
+        OperationResourceInfo ori1 = new OperationResourceInfo(
+                                                               TestClass.class.getMethod("doIt",
new Class[]{}), 
+                                                               new ClassResourceInfo(TestClass.class));
+        ori1.setURITemplate(new URITemplate("/"));
+        
+        OperationResourceInfo ori2 = new OperationResourceInfo(
+                                                               TestClass.class.getMethod("doThat",
new Class[]{}), 
+                                                               new ClassResourceInfo(TestClass.class));
+        
+        ori2.setURITemplate(new URITemplate("/"));
+        
+        OperationResourceInfoComparator cmp = new OperationResourceInfoComparator(m, "POST",
false,
+            MediaType.WILDCARD_TYPE, Collections.singletonList(MediaType.WILDCARD_TYPE));
+        
+        
+        int result = cmp.compare(ori1,  ori2);
+        assertEquals(0, result);
+    }
+    
+    
+    private Message createMessage() {
+        Message m = new MessageImpl();
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.get("org.apache.cxf.jaxrs.comparator");
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
 }



Mime
View raw message