cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1337204 - in /cxf/trunk/tools/wadlto/jaxrs/src: main/java/org/apache/cxf/tools/wadlto/jaxrs/ test/java/org/apache/cxf/tools/wadlto/jaxrs/ test/resources/wadl/
Date Fri, 11 May 2012 15:18:53 GMT
Author: sergeyb
Date: Fri May 11 15:18:52 2012
New Revision: 1337204

URL: http://svn.apache.org/viewvc?rev=1337204&view=rev
Log:
[CXF-4311] Attempting to generate the unique method names when no method ids are available

Added:
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml 
 (with props)
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml   (with props)
Modified:
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1337204&r1=1337203&r2=1337204&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri May 11 15:18:52 2012
@@ -488,8 +488,12 @@ public class SourceGenerator {
     
     private String firstCharToUpperCase(String name) {
         StringBuilder sb = new StringBuilder();
-        sb.append(Character.toUpperCase(name.charAt(0)));
-        return name.length() > 1 ? sb.append(name.substring(1)).toString() : sb.toString();
+        if (name.length() > 0) {
+            sb.append(Character.toUpperCase(name.charAt(0)));
+            return name.length() > 1 ? sb.append(name.substring(1)).toString() : sb.toString();
+        } else {
+            return sb.toString();
+        }
     }
     
     private boolean writeAnnotations(boolean interfaceIsGenerated) {
@@ -638,7 +642,11 @@ public class SourceGenerator {
             boolean responseTypeAvailable = true;
             if (methodNameLowerCase.length() > 0) {
                 responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, info);
-                sbCode.append(id + suffixName);
+                String genMethodName = id + suffixName;
+                if (methodNameLowerCase.equals(genMethodName)) {
+                    genMethodName += firstCharToUpperCase(currentPath.replaceAll("/", ""));
+                }
+                sbCode.append(genMethodName);
             } else {
                 boolean expandedQName = id.startsWith("{");
                 QName qname = convertToQName(id, expandedQName);

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1337204&r1=1337203&r2=1337204&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Fri May 11 15:18:52 2012
@@ -332,6 +332,66 @@ public class JAXRSContainerTest extends 
     }
     
     @Test    
+    public void testCodeGenNoIds3() {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourcesNoId.xml"));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+            
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java"
+ "$");
+            assertEquals(1, javaFiles.size());
+            assertTrue(checkContains(javaFiles, "application.TestRsResource.java"));
+            List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
+            assertEquals(1, classFiles.size());
+            assertTrue(checkContains(classFiles, "application.TestRsResource.class"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
+    @Test    
+    public void testCodeTwoSchemasSameTargetNs() {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSameTargetNsSchemas.xml"));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+            
+            container.setContext(context);
+            container.execute();
+
+            List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java"
+ "$");
+            assertEquals(4, javaFiles.size());
+            assertTrue(checkContains(javaFiles, "application.Resource.java"));
+            assertTrue(checkContains(javaFiles, "com.example.test.ObjectFactory.java"));
+            assertTrue(checkContains(javaFiles, "com.example.test.package-info.java"));
+            assertTrue(checkContains(javaFiles, "com.example.test.TestCompositeObject.java"));
+            List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
+            assertEquals(4, classFiles.size());
+            assertTrue(checkContains(classFiles, "application.Resource.class"));
+            assertTrue(checkContains(classFiles, "com.example.test.ObjectFactory.class"));
+            assertTrue(checkContains(classFiles, "com.example.test.package-info.class"));
+            assertTrue(checkContains(classFiles, "com.example.test.TestCompositeObject.class"));
+
+            
+            assertNotNull(output.list());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    @Test    
     public void testCodeGenWithResourceSet() {
         try {
             JAXRSContainer container = new JAXRSContainer(null);

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml?rev=1337204&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml Fri
May 11 15:18:52 2012
@@ -0,0 +1,31 @@
+<application xmlns="http://wadl.dev.java.net/2009/02" 
+ xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+ xmlns:ns1="http://example.com/test"><doc title="My Application"/>
+  <grammars>
+   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"

+    elementFormDefault="unqualified"  targetNamespace="http://example.com/test">
+    <xs:complexType name="testCompositeObject">
+        <xs:sequence>
+            <xs:element name="id" type="xs:int"/>
+            <xs:element minOccurs="0" name="name" type="xs:string"/>
+        </xs:sequence>
+    </xs:complexType>
+  </xs:schema>
+  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/test"
attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://example.com/test">
+    <xs:import/>
+    <xs:element name="test" type="testCompositeObject"/>
+  </xs:schema>
+</grammars>
+<resources base="http://localhost:8080/baz">
+<resource path="/"><resource path="setTest3"><method name="PUT">
+  <request>
+    <representation mediaType="application/xml" element="ns1:test"/>
+  </request>
+  <response>
+    <representation mediaType="application/xml" element="ns1:test"/>
+  </response>
+  </method>
+  </resource>
+  </resource>
+</resources>
+</application>
\ No newline at end of file

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourceSameTargetNsSchemas.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml?rev=1337204&view=auto
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml (added)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml Fri May 11 15:18:52
2012
@@ -0,0 +1,25 @@
+<application xmlns="http://wadl.dev.java.net/2009/02" 
+             xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ 
+  <resources base="http://localhost:8080/baz">
+       <resource path="/TestRs">
+          <resource path="/helloWorld">
+           <method name="GET">
+           <response>
+             <representation mediaType="application/octet-stream">
+               <param name="result" style="plain" type="xs:string"/>
+             </representation></response>
+           </method>
+          </resource>
+          <resource path="/helloWorld2">
+           <method name="GET">
+            <response>
+              <representation mediaType="application/octet-stream">
+                <param name="result" style="plain" type="xs:string"/>
+              </representation>
+            </response>
+           </method>
+          </resource>
+        </resource>
+  </resources>
+</application>
\ No newline at end of file

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message