cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r893773 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/model/wadl/ main/java/org/apache/cxf/jaxrs/provider/ test/java/org/apache/cxf/jaxrs/impl/ test/java/org/apache/cxf/jaxrs/mode...
Date Thu, 24 Dec 2009 15:21:00 GMT
Author: sergeyb
Date: Thu Dec 24 15:20:55 2009
New Revision: 893773

URL: http://svn.apache.org/viewvc?rev=893773&view=rev
Log:
JAXRS: enhancing WADL test and making sure a custom WadlGenerator can be plugged-in

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Thu Dec 24 15:20:55 2009
@@ -29,7 +29,10 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.message.Message;
 
@@ -161,9 +164,14 @@
             String requestURI = (String)m.get(Message.REQUEST_URI);
             String baseAddress = HttpUtils.getBaseAddress(m);
             if (baseAddress.equals(requestURI)) {
-                Response r = new WadlGenerator().handleRequest(m, null);
-                if (r != null) {
-                    m.getExchange().put(Response.class, r);
+                List<ProviderInfo<RequestHandler>> shs = ProviderFactory.getInstance(m).getRequestHandlers();
+                // this is actually being tested by ProviderFactory unit tests but just in
case
+                // WadlGenerator, the custom or default one, must be the first one
+                if (shs.size() > 0 && shs.get(0).getProvider() instanceof WadlGenerator)
{
+                    Response r = shs.get(0).getProvider().handleRequest(m, null);
+                    if (r != null) {
+                        m.getExchange().put(Response.class, r);
+                    }    
                 }
             }
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Thu Dec 24 15:20:55 2009
@@ -202,7 +202,7 @@
                 if (subcri != null && !visitedResources.contains(subcri)) {
                     String path = ori.getURITemplate().getValue();
                     sb.append("<resource path=\"").append(path).append("\">");
-                    handleDocs(cri.getServiceClass().getAnnotations(), sb);
+                    handleDocs(subcri.getServiceClass().getAnnotations(), sb);
                     handlePathAndMatrixParams(sb, ori);
                     handleResource(sb, jaxbTypes, jaxbProxy, clsMap, subcri, 
                                    visitedResources);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Dec 24 15:20:55 2009
@@ -280,15 +280,26 @@
                                                         parameterAnnotations, mediaType,
m);
     }
     
-    
-    
     public List<ProviderInfo<RequestHandler>> getRequestHandlers() {
         List<ProviderInfo<RequestHandler>> handlers = null;
         if (requestHandlers.size() == 0) {
             handlers = SHARED_FACTORY.requestHandlers;
         } else {
-            handlers = new ArrayList<ProviderInfo<RequestHandler>>(SHARED_FACTORY.requestHandlers);
+            handlers = new ArrayList<ProviderInfo<RequestHandler>>();
+            boolean customWADLHandler = false;
+            for (int i = 0; i < requestHandlers.size(); i++) {
+                if (requestHandlers.get(i).getProvider() instanceof WadlGenerator) {
+                    customWADLHandler = true;
+                    break;
+                }
+            }
+            if (!customWADLHandler) {
+                // TODO : this works only because we know we only have a single 
+                // system handler which is a default WADLGenerator, think of a better approach
+                handlers.addAll(SHARED_FACTORY.requestHandlers);    
+            }
             handlers.addAll(requestHandlers);
+            
         }
         return Collections.unmodifiableList(handlers);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
Thu Dec 24 15:20:55 2009
@@ -24,9 +24,22 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 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.apache.cxf.service.Service;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.servlet.ServletDestination;
 import org.easymock.classextension.EasyMock;
@@ -65,6 +78,20 @@
     }
     
     @Test
+    public void testWadlQuery() {
+        Message m = mockMessage("http://localhost:8080/bar", "/bar", "_wadl", "GET");
+        ClassResourceInfo cri = 
+            ResourceUtils.createClassResourceInfo(TestResource.class, TestResource.class,
true, true);
+        m.getExchange().put(Service.class, new JAXRSServiceImpl(Collections.singletonList(cri)));
+        RequestPreprocessor sqh = new RequestPreprocessor();
+        sqh.preprocess(m, new UriInfoImpl(m, null));
+        Response r = m.getExchange().get(Response.class);
+        assertNotNull(r);
+        assertEquals(WadlGenerator.WADL_TYPE.toString(),
+                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
+    }
+    
+    @Test
     public void testTypeQuery() {
         Message m = mockMessage("http://localhost:8080", "/bar", "_type=xml", "POST");
         RequestPreprocessor sqh = new RequestPreprocessor();
@@ -86,12 +113,15 @@
                                 String method,
                                 String methodHeader) {
         Message m = new MessageImpl();
-        control.reset();
-        Exchange e = control.createMock(Exchange.class);
+        Exchange e = new ExchangeImpl();
         m.setExchange(e);
+        control.reset();
+        Endpoint endp = control.createMock(Endpoint.class);
+        e.put(Endpoint.class, endp);
+        endp.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).anyTimes();
         ServletDestination d = control.createMock(ServletDestination.class);
-        e.getDestination();
-        EasyMock.expectLastCall().andReturn(d).anyTimes();
+        e.setDestination(d);
         EndpointInfo epr = new EndpointInfo(); 
         epr.setAddress(baseAddress);
         d.getEndpointInfo();
@@ -107,4 +137,12 @@
         control.replay();
         return m;
     }
+    
+    @Path("/test")
+    private static class TestResource {
+        @GET
+        public String get() {
+            return "test";
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Thu Dec 24 15:20:55 2009
@@ -142,21 +142,45 @@
                                                           XmlSchemaConstants.XSD_NAMESPACE_URI,
"schema");
         assertEquals(1, schemasEls.size());
         assertEquals("http://superbooks", schemasEls.get(0).getAttribute("targetNamespace"));
-        assertEquals(3, DOMUtils.getChildrenWithName(schemasEls.get(0), 
-                       XmlSchemaConstants.XSD_NAMESPACE_URI, "element").size());
-        assertEquals(3, DOMUtils.getChildrenWithName(schemasEls.get(0), 
-                       XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType").size());
+        List<Element> elementEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

+                            XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
+        assertEquals(3, elementEls.size());
+        assertTrue(checkElement(elementEls, "thebook", "tns:book"));
+        assertTrue(checkElement(elementEls, "thebook2", "tns:book2"));
+        assertTrue(checkElement(elementEls, "thechapter", "tns:chapter"));
+        
+        List<Element> complexTypesEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

+                                        XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType");
+        assertEquals(3, complexTypesEls.size());
+        
+        assertTrue(checkComplexType(complexTypesEls, "book"));
+        assertTrue(checkComplexType(complexTypesEls, "book2"));
+        assertTrue(checkComplexType(complexTypesEls, "chapter"));
+    }
+    
+    private boolean checkComplexType(List<Element> els, String name) {
+        for (Element e : els) {
+            if (name.equals(e.getAttribute("name"))) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private boolean checkElement(List<Element> els, String name, String type) {
+        for (Element e : els) {
+            if (name.equals(e.getAttribute("name"))
+                && type.equals(e.getAttribute("type"))) {
+                return true;
+            }
+        }
+        return false;
     }
     
     private void checkBookStoreInfo(Element resource) {
         assertEquals("/bookstore/{id}", resource.getAttribute("path"));
         
-        List<Element> docsEls = DOMUtils.getChildrenWithName(resource, 
-                WadlGenerator.WADL_NS, "doc");
-        assertEquals(1, docsEls.size());
-        assertEquals("book store resource", docsEls.get(0).getAttribute("title"));
-        assertEquals("en-us", 
-            docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
+        checkRootDocs(resource);
         
         List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, 
                                          WadlGenerator.WADL_NS, "resource");
@@ -169,75 +193,178 @@
         assertEquals("/booksubresource", resourceEls.get(5).getAttribute("path"));
         assertEquals("/itself", resourceEls.get(6).getAttribute("path"));
         
+        // verify repource starting with "/"
+        // must have a single template parameter
+        List<Element> paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

+                                                               WadlGenerator.WADL_NS, "param");
+        assertEquals(1, paramsEls.size());
+        checkParameter(paramsEls.get(0), "id", "template", "xs:long");
         
+        // must have 2 methods, GET and PUT
         List<Element> methodEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

                                                                WadlGenerator.WADL_NS, "method");
-        
         assertEquals(2, methodEls.size());
-        assertEquals("GET", methodEls.get(0).getAttribute("name"));
-        assertEquals("PUT", methodEls.get(1).getAttribute("name"));
-        
-        List<Element> paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

-                                                               WadlGenerator.WADL_NS, "param");
-        assertEquals(1, paramsEls.size());
-        checkParameter(paramsEls.get(0), "id", "template");
         
+        // verify GET
+        assertEquals("GET", methodEls.get(0).getAttribute("name"));
+        assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), 
+                        WadlGenerator.WADL_NS, "param").size());
+        // check request 
         List<Element> requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
                                                                WadlGenerator.WADL_NS, "request");
         assertEquals(1, requestEls.size());
         
+        // 6 parameters are expected
         paramsEls = DOMUtils.getChildrenWithName(requestEls.get(0), 
                                                  WadlGenerator.WADL_NS, "param");
         assertEquals(6, paramsEls.size());
-        checkParameter(paramsEls.get(0), "a", "query");
-        checkParameter(paramsEls.get(1), "b", "query");
-        checkParameter(paramsEls.get(2), "c.a", "query");
-        checkParameter(paramsEls.get(3), "c.b", "query");
-        checkParameter(paramsEls.get(4), "c.d.a", "query");
-        checkParameter(paramsEls.get(5), "c.d.b", "query");
+        checkParameter(paramsEls.get(0), "a", "query", "xs:int");
+        checkParameter(paramsEls.get(1), "b", "query", "xs:int");
+        checkParameter(paramsEls.get(2), "c.a", "query", "xs:int");
+        checkParameter(paramsEls.get(3), "c.b", "query", "xs:int");
+        checkParameter(paramsEls.get(4), "c.d.a", "query", "xs:int");
+        checkParameter(paramsEls.get(5), "c.d.b", "query", "xs:int");
+        assertEquals(0, DOMUtils.getChildrenWithName(requestEls.get(0), 
+                         WadlGenerator.WADL_NS, "representation").size());
+        //check response
+        verifyPlainRepresentation(methodEls.get(0), "response");
+        
+        // verify PUT
+        assertEquals("PUT", methodEls.get(1).getAttribute("name"));
+        verifyPlainRepresentation(methodEls.get(1), "request");
+        
+        verifyResponseWithStatus(methodEls.get(1), "204");
         
+        // verify resource starting with /book2
+        verifyGetResourceMethod(resourceEls.get(1), "prefix1:thebook2");
+        
+        //verify resource starting with /books/{bookid}
         paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(2), 
                                                                WadlGenerator.WADL_NS, "param");
+        // should have 3 parameters
         assertEquals(3, paramsEls.size());
-        checkParameter(paramsEls.get(0), "id", "template");
-        checkParameter(paramsEls.get(1), "bookid", "template");
-        checkParameter(paramsEls.get(2), "mid", "matrix");
+        checkParameter(paramsEls.get(0), "id", "template", "xs:int");
+        checkParameter(paramsEls.get(1), "bookid", "template", "xs:int");
+        checkParameter(paramsEls.get(2), "mid", "matrix", "xs:int");
         
+        // and 2 methods
         methodEls = DOMUtils.getChildrenWithName(resourceEls.get(2), 
                                                  WadlGenerator.WADL_NS, "method");
         assertEquals(2, methodEls.size());
         
+        // POST 
         assertEquals("POST", methodEls.get(0).getAttribute("name"));
         
-        requestEls = DOMUtils.getChildrenWithName(methodEls.get(1), 
-                                                                WadlGenerator.WADL_NS, "request");
+        requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
+                                             WadlGenerator.WADL_NS, "request");
         assertEquals(1, requestEls.size());
-        List<Element> repEls = DOMUtils.getChildrenWithName(requestEls.get(0), 
-                                                            WadlGenerator.WADL_NS, "representation");
-        assertEquals(2, repEls.size());
-        assertEquals("application/xml", repEls.get(0).getAttribute("mediaType"));
-        assertEquals("prefix1:thebook", repEls.get(0).getAttribute("element"));
-        assertEquals("application/json", repEls.get(1).getAttribute("mediaType"));
-        assertEquals("", repEls.get(1).getAttribute("element"));
+        paramsEls = DOMUtils.getChildrenWithName(requestEls.get(0), 
+                                                 WadlGenerator.WADL_NS, "param");
+        // should have 2 parameters
+        assertEquals(2, paramsEls.size());
+        checkParameter(paramsEls.get(0), "hid", "header", "xs:int");
+        checkParameter(paramsEls.get(1), "provider.bar", "query", "xs:int");
+        verifyXmlJsonRepresentations(requestEls.get(0), "prefix1:thebook");
         
+        // PUT
         assertEquals("PUT", methodEls.get(1).getAttribute("name"));
-        
-        requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
+        requestEls = DOMUtils.getChildrenWithName(methodEls.get(1), 
                                                                 WadlGenerator.WADL_NS, "request");
         assertEquals(1, requestEls.size());
-        repEls = DOMUtils.getChildrenWithName(requestEls.get(0), 
+        verifyXmlJsonRepresentations(requestEls.get(0), "prefix1:thebook");
+        verifyResponseWithStatus(methodEls.get(1), "204");
+        
+        // verify resource starting with /chapter
+        verifyGetResourceMethod(resourceEls.get(3), "prefix1:thechapter");
+        
+        // verify resource starting from /booksubresource
+        // should have 2 parameters
+        paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(5), 
+                         WadlGenerator.WADL_NS, "param");
+        assertEquals(2, paramsEls.size());
+        checkParameter(paramsEls.get(0), "id", "template", "xs:int");
+        checkParameter(paramsEls.get(1), "mid", "matrix", "xs:int");
+        
+        // should have 4 child resources
+        List<Element> subResourceEls = DOMUtils.getChildrenWithName(resourceEls.get(5),

+                                         WadlGenerator.WADL_NS, "resource");
+        assertEquals(4, subResourceEls.size());        
+        assertEquals("/book", subResourceEls.get(0).getAttribute("path"));
+        assertEquals("/form1", subResourceEls.get(1).getAttribute("path"));
+        assertEquals("/form2", subResourceEls.get(2).getAttribute("path"));
+        assertEquals("/chapter/{cid}", subResourceEls.get(3).getAttribute("path"));
+        // verify subresource /book
+        // GET 
+        verifyGetResourceMethod(subResourceEls.get(0), "prefix1:thebook");
+        
+        // verify subresource /chapter/{id}
+        List<Element> chapterMethodEls = DOMUtils.getChildrenWithName(subResourceEls.get(3),

+                                                                    WadlGenerator.WADL_NS,
"resource");
+        assertEquals(1, chapterMethodEls.size());        
+        assertEquals("/id", chapterMethodEls.get(0).getAttribute("path"));
+        paramsEls = DOMUtils.getChildrenWithName(subResourceEls.get(3), 
+                                                 WadlGenerator.WADL_NS, "param");
+        assertEquals(1, paramsEls.size());
+        checkParameter(paramsEls.get(0), "cid", "template", "xs:int");
+        // GET
+        verifyGetResourceMethod(chapterMethodEls.get(0), "prefix1:thechapter");
+    }
+    
+    private void checkRootDocs(Element el) {
+        List<Element> docsEls = DOMUtils.getChildrenWithName(el, 
+                                                             WadlGenerator.WADL_NS, "doc");
+        assertEquals(1, docsEls.size());
+        assertEquals("book store resource", docsEls.get(0).getAttribute("title"));
+        assertEquals("en-us", 
+            docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
+    }
+    
+    private void verifyGetResourceMethod(Element element, String type) {
+        List<Element> methodEls = DOMUtils.getChildrenWithName(element, WadlGenerator.WADL_NS,
"method");
+        assertEquals(1, methodEls.size());
+        assertEquals("GET", methodEls.get(0).getAttribute("name"));
+        assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), 
+                      WadlGenerator.WADL_NS, "request").size());
+        List<Element> responseEls = DOMUtils.getChildrenWithName(methodEls.get(0),

+                                WadlGenerator.WADL_NS, "response");
+        assertEquals(1, responseEls.size());
+        verifyXmlJsonRepresentations(responseEls.get(0), type);
+    }
+    
+    private void verifyResponseWithStatus(Element element, String status) {
+        List<Element> responseEls = DOMUtils.getChildrenWithName(element, 
+                                       WadlGenerator.WADL_NS, "response");
+        assertEquals(1, responseEls.size());
+        assertEquals(status, responseEls.get(0).getAttribute("status"));
+        assertEquals(0, DOMUtils.getChildrenWithName(responseEls.get(0), 
+            WadlGenerator.WADL_NS, "representation").size());
+    }
+    
+    private void verifyPlainRepresentation(Element element, String name) {
+        List<Element> responseEls = DOMUtils.getChildrenWithName(element, 
+                                 WadlGenerator.WADL_NS, name);
+        assertEquals(1, responseEls.size());
+        List<Element> representationEls = DOMUtils.getChildrenWithName(responseEls.get(0),

+                    WadlGenerator.WADL_NS, "representation"); 
+        assertEquals(1, representationEls.size());
+        assertEquals("text/plain", representationEls.get(0).getAttribute("mediaType"));
+        assertEquals("", representationEls.get(0).getAttribute("element"));
+    }
+    
+    private void verifyXmlJsonRepresentations(Element element, String type) {
+        List<Element> repEls = DOMUtils.getChildrenWithName(element, 
                                                             WadlGenerator.WADL_NS, "representation");
         assertEquals(2, repEls.size());
         assertEquals("application/xml", repEls.get(0).getAttribute("mediaType"));
-        assertEquals("prefix1:thebook", repEls.get(0).getAttribute("element"));
+        assertEquals(type, repEls.get(0).getAttribute("element"));
         assertEquals("application/json", repEls.get(1).getAttribute("mediaType"));
         assertEquals("", repEls.get(1).getAttribute("element"));
-        
     }
     
-    private void checkParameter(Element paramEl, String name, String type) {
+    private void checkParameter(Element paramEl, String name, String style, String type)
{
         assertEquals(name, paramEl.getAttribute("name"));
-        assertEquals(type, paramEl.getAttribute("style"));    
+        assertEquals(style, paramEl.getAttribute("style"));
+        assertEquals(type, paramEl.getAttribute("type"));
     }
     
     private List<Element> getWadlResourcesInfo(Document doc, String baseURI, int size)
throws Exception {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
Thu Dec 24 15:20:55 2009
@@ -23,13 +23,17 @@
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
+import org.apache.cxf.jaxrs.ext.Description;
+
 @XmlRootElement(name = "thebook", namespace = "http://superbooks")
 @XmlType(name = "book", namespace = "http://superbooks")
+@Description("Book subresource")
 public class Book {
 
     private int id;
@@ -45,14 +49,20 @@
     
     @GET
     @Path("/book")
-    public int getId() {
-        return id;
+    @Produces({"application/xml", "application/json" })
+    @Description("Get the book")
+    public Book getIt() {
+        return this;
     }
     
     public void setId(int ident) {
         id = ident;
     }
     
+    public int getId() {
+        return id;
+    }
+    
     @Path("/chapter/{cid}")
     public Chapter getChapter(@PathParam("cid") int cid) {
         return chapter;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
Thu Dec 24 15:20:55 2009
@@ -20,11 +20,15 @@
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
+import org.apache.cxf.jaxrs.ext.Description;
+
 @XmlRootElement(name = "thechapter", namespace = "http://superbooks")
 @XmlType(name = "chapter", namespace = "http://superbooks")
+@Description("Chapter subresource")
 public class Chapter {
 
     private int id;
@@ -36,12 +40,18 @@
     
     @GET
     @Path("/id")
-    public int getId() {
-        return id;
+    @Produces({"application/xml", "application/json" })
+    @Description("Get the chapter")
+    public Chapter getIt() {
+        return this;
     }
     
     public void setId(int ident) {
         id = ident;
     }
+    
+    public int getId() {
+        return id;
+    }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=893773&r1=893772&r2=893773&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Thu Dec 24 15:20:55 2009
@@ -52,8 +52,11 @@
 import org.apache.cxf.jaxrs.CustomerParameterHandler;
 import org.apache.cxf.jaxrs.JAXBContextProvider;
 import org.apache.cxf.jaxrs.ext.ParameterHandler;
+import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.SuperBook;
 import org.apache.cxf.message.Exchange;
@@ -82,6 +85,49 @@
     }
     
     @Test
+    public void testCustomWadlHandler() {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        assertEquals(1, pf.getRequestHandlers().size());
+        assertTrue(pf.getRequestHandlers().get(0).getProvider() instanceof WadlGenerator);
+        
+        WadlGenerator wg = new WadlGenerator();
+        pf.setUserProviders(Collections.singletonList(wg));
+        assertEquals(1, pf.getRequestHandlers().size());
+        assertTrue(pf.getRequestHandlers().get(0).getProvider() instanceof WadlGenerator);
+        assertSame(wg, pf.getRequestHandlers().get(0).getProvider());
+    }
+    
+    @Test
+    public void testCustomTestHandler() {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        assertEquals(1, pf.getRequestHandlers().size());
+        assertTrue(pf.getRequestHandlers().get(0).getProvider() instanceof WadlGenerator);
+        
+        TestHandler th = new TestHandler();
+        pf.setUserProviders(Collections.singletonList(th));
+        assertEquals(2, pf.getRequestHandlers().size());
+        assertTrue(pf.getRequestHandlers().get(0).getProvider() instanceof WadlGenerator);
+        assertSame(th, pf.getRequestHandlers().get(1).getProvider());
+    }
+    
+    @Test
+    public void testCustomTestAndWadlHandler() {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        assertEquals(1, pf.getRequestHandlers().size());
+        assertTrue(pf.getRequestHandlers().get(0).getProvider() instanceof WadlGenerator);
+        
+        List<Object> providers = new ArrayList<Object>();
+        WadlGenerator wg = new WadlGenerator();
+        providers.add(wg);
+        TestHandler th = new TestHandler();
+        providers.add(th);
+        pf.setUserProviders(providers);
+        assertEquals(2, pf.getRequestHandlers().size());
+        assertSame(wg, pf.getRequestHandlers().get(0).getProvider());
+        assertSame(th, pf.getRequestHandlers().get(1).getProvider());
+    }
+    
+    @Test
     public void testSchemaLocations() {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.setSchemaLocations(Collections.singletonList("classpath:/test.xsd"));
@@ -556,4 +602,11 @@
         
     }
     
+    private static class TestHandler implements RequestHandler {
+
+        public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
+            return null;
+        }
+        
+    }
 }



Mime
View raw message