cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [cxf] 01/02: Update TypeVariable check ResourceUtils.java and UnitTest
Date Tue, 21 Nov 2017 12:55:37 GMT
This is an automated email from the ASF dual-hosted git repository.

sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit e08292351231f9c7127a01e846b9c7d4e1023f70
Author: Evaristo Wychoski Benfatti <evaristo@ubuntu-server>
AuthorDate: Mon Nov 20 10:04:24 2017 -0200

    Update TypeVariable check ResourceUtils.java and UnitTest
---
 .../org/apache/cxf/jaxrs/utils/ResourceUtils.java  |   4 +-
 .../cxf/jaxrs/model/wadl/WadlGeneratorTest.java    | 120 +++++++++++++++++++++
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index e280c89..6a980e3 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -27,6 +27,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -685,7 +686,8 @@ public final class ResourceUtils {
             type = InjectionUtils.getActualType(genericType);
             isCollection = true;
         }
-        if (type == Object.class && !(genericType instanceof Class)) {
+        if (type == Object.class && !(genericType instanceof Class)
+            || genericType instanceof TypeVariable) {
             Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass,
                                                       Object.class,
                                                       genericType);
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
index 7086461..8cd7227 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
@@ -44,6 +44,7 @@ import org.apache.cxf.endpoint.EndpointImpl;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -936,4 +937,123 @@ public class WadlGeneratorTest extends Assert {
             return transfer;
         }
     }
+
+    @XmlRootElement(namespace = "http://example.com")
+    public static class Super {
+        private int id;
+        private String name;
+        public int getId() {
+            return id;
+        }
+        public void setId(int id) {
+            this.id = id;
+        }
+        public String getName() {
+            return name;
+        }
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    public static class SuperResource<T extends Super> {
+
+        @PUT
+        @Path("set")
+        @Produces("application/xml")
+        @Consumes("application/xml")
+        public T set(T transfer) {
+            return transfer;
+        }
+
+    }
+
+    @XmlRootElement(namespace = "http://example.com")
+    public static class Actual extends Super { }
+
+    public static class ActualResource extends SuperResource<Actual> { }
+
+    private void setUpGenericImplementationTest() {
+        ServerProviderFactory.getInstance().clearProviders();
+        AbstractResourceInfo.clearAllMaps();
+    }
+
+    @Test
+    public void testGenericImplementation() throws Exception {
+        setUpGenericImplementationTest();
+
+        WadlGenerator wg = new WadlGenerator();
+        wg.setApplicationTitle("My Application");
+        wg.setNamespacePrefix("ns");
+        ClassResourceInfo cri =
+            ResourceUtils.createClassResourceInfo(ActualResource.class, ActualResource.class,
true, true);
+        Message m = mockMessage("http://example.com", "/", WadlGenerator.WADL_QUERY, cri);
+        Response r = handleRequest(wg, m);
+        checkResponse(r);
+        Document doc = StaxUtils.read(new StringReader(r.getEntity().toString()));
+        checkDocs(doc.getDocumentElement(), "My Application", "", "");
+        List<Element> grammarEls = DOMUtils.getChildrenWithName(doc.getDocumentElement(),
+                                                                WadlGenerator.WADL_NS,
+                                                                "grammars");
+        assertEquals(1, grammarEls.size());
+        List<Element> schemasEls = DOMUtils.getChildrenWithName(grammarEls.get(0),
+                                                                Constants.URI_2001_SCHEMA_XSD,
+                                                                "schema");
+        assertEquals(2, schemasEls.size());
+        assertEquals("http://example.com", schemasEls.get(0).getAttribute("targetNamespace"));
+        assertEquals("http://example.com", schemasEls.get(1).getAttribute("targetNamespace"));
+
+        List<Element> importEls = DOMUtils.getChildrenWithName(schemasEls.get(0),
+                Constants.URI_2001_SCHEMA_XSD,
+                "import");
+        assertEquals(1, importEls.size());
+
+        List<Element> typeEls = DOMUtils.getChildrenWithName(schemasEls.get(0),
+                Constants.URI_2001_SCHEMA_XSD,
+                "element");
+        assertEquals(2, typeEls.size());
+        assertEquals("actual", typeEls.get(0).getAttribute("name"));
+        assertEquals("actual", typeEls.get(0).getAttribute("type"));
+        assertEquals("super", typeEls.get(1).getAttribute("name"));
+        assertEquals("super", typeEls.get(1).getAttribute("type"));
+
+        List<Element> complexTypeEls = DOMUtils.getChildrenWithName(schemasEls.get(1),
+                Constants.URI_2001_SCHEMA_XSD,
+                "complexType");
+        assertEquals(2, complexTypeEls.size());
+        assertEquals("actual", complexTypeEls.get(0).getAttribute("name"));
+        assertEquals("super", complexTypeEls.get(1).getAttribute("name"));
+
+        Element ccActualElement =
+                (Element)complexTypeEls.get(0).getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD,
+                                                  "complexContent").item(0);
+        Element extensionActualElement =
+            (Element)ccActualElement.getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD,
+                                              "extension").item(0);
+        Element sequenceActualElement =
+                (Element)ccActualElement.getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD,
+                                                  "sequence").item(0);
+        assertEquals("super", extensionActualElement.getAttribute("base"));
+        assertEquals(0, sequenceActualElement.getChildNodes().getLength());
+
+        Element sequenceSuperElement =
+                (Element)complexTypeEls.get(1).getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD,
+                                                  "sequence").item(0);
+        List<Element> superEls = DOMUtils.getChildrenWithName(sequenceSuperElement,
+                Constants.URI_2001_SCHEMA_XSD,
+                "element");
+        assertEquals(2, superEls.size());
+        assertEquals("id", superEls.get(0).getAttribute("name"));
+        assertEquals("xs:int", superEls.get(0).getAttribute("type"));
+        assertEquals("name", superEls.get(1).getAttribute("name"));
+        assertEquals("xs:string", superEls.get(1).getAttribute("type"));
+
+        List<Element> reps = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(),
+                                       WadlGenerator.WADL_NS, "representation");
+        assertEquals(2, reps.size());
+        assertEquals("ns1:actual", reps.get(0).getAttribute("element"));
+        assertEquals("ns1:actual", reps.get(1).getAttribute("element"));
+
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@cxf.apache.org" <commits@cxf.apache.org>.

Mime
View raw message