You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/07/15 20:04:20 UTC

svn commit: r1503382 - in /cxf/branches/2.6.x-fixes/tools: common/src/main/java/org/apache/cxf/tools/common/ common/src/main/java/org/apache/cxf/tools/util/ corba/src/test/java/org/apache/cxf/tools/corba/processors/ corba/src/test/java/org/apache/cxf/t...

Author: dkulp
Date: Mon Jul 15 18:04:20 2013
New Revision: 1503382

URL: http://svn.apache.org/r1503382
Log:
Merged revisions 1503350 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1503350 | dkulp | 2013-07-15 13:12:15 -0400 (Mon, 15 Jul 2013) | 10 lines

  Merged revisions 1502891 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1502891 | dkulp | 2013-07-13 17:29:51 -0400 (Sat, 13 Jul 2013) | 2 lines

    Fix how the wsdls are parsed to try and process qnames as qnames, not strings, so namespace prefixes can be irrelevant.

  ........

........

Modified:
    cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
    cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
    cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/IDLToWSDLGenerationTest.java
    cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/WSDLToCorbaBindingTest.java
    cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/utils/WSDLGenerationTester.java

Modified: cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java?rev=1503382&r1=1503381&r2=1503382&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java (original)
+++ cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ProcessorTestBase.java Mon Jul 15 18:04:20 2013
@@ -23,7 +23,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -31,9 +30,12 @@ import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
@@ -43,6 +45,8 @@ import javax.xml.namespace.QName;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.tools.util.ToolsStaxUtils;
+import org.apache.ws.commons.schema.constants.Constants;
+
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.ComparisonFailure;
@@ -71,7 +75,20 @@ public class ProcessorTestBase extends A
 
     protected File output;
     protected ToolContext env = new ToolContext();
-
+    protected Map<QName, Set<String>> qnameAtts = new HashMap<QName, Set<String>>();
+    
+    public ProcessorTestBase() {
+        addQNameAttribute(new QName(Constants.URI_2001_SCHEMA_XSD, "element"), "type");
+    }
+    
+    protected final void addQNameAttribute(QName element, String local) {
+        Set<String> a = qnameAtts.get(element);
+        if (a == null) {
+            qnameAtts.put(element, new HashSet<String>());
+            a = qnameAtts.get(element);
+        }
+        a.add(local);
+    }
 
     @After
     public void tearDown() {
@@ -296,7 +313,7 @@ public class ProcessorTestBase extends A
                 }
                 Tag sourceTag = getFromSource(source, expectedTag);
                 if (sourceTag == null) {
-                    throw new AssertionError("\n" + expected.toString()
+                    throw new AssertionError("\n" + expectedTag.toString()
                                              + " is missing in the source file:"
                                              + "\n" + source.toString());
                 }
@@ -316,8 +333,8 @@ public class ProcessorTestBase extends A
 
     public void assertWsdlEquals(final File expected, final File source, List<String> attr, List<String> tag)
         throws Exception {
-        Tag expectedTag = ToolsStaxUtils.getTagTree(expected, attr);
-        Tag sourceTag = ToolsStaxUtils.getTagTree(source, attr);
+        Tag expectedTag = ToolsStaxUtils.getTagTree(expected, attr, qnameAtts);
+        Tag sourceTag = ToolsStaxUtils.getTagTree(source, attr, qnameAtts);
         assertTagEquals(expectedTag, sourceTag, attr, tag);
     }
 
@@ -328,8 +345,8 @@ public class ProcessorTestBase extends A
     public void assertWsdlEquals(final InputStream expected, final InputStream source,
                                  List<String> attr, List<String> tag)
         throws Exception {
-        Tag expectedTag = ToolsStaxUtils.getTagTree(expected, attr);
-        Tag sourceTag = ToolsStaxUtils.getTagTree(source, attr);
+        Tag expectedTag = ToolsStaxUtils.getTagTree(expected, attr, qnameAtts);
+        Tag sourceTag = ToolsStaxUtils.getTagTree(source, attr, qnameAtts);
         assertTagEquals(expectedTag, sourceTag, attr, tag);
     }
 

Modified: cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java?rev=1503382&r1=1503381&r2=1503382&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java (original)
+++ cxf/branches/2.6.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ToolsStaxUtils.java Mon Jul 15 18:04:20 2013
@@ -26,7 +26,10 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.Stack;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 
@@ -101,9 +104,17 @@ public final class ToolsStaxUtils {
 
     public static Tag getTagTree(final File source, final List<String> ignoreAttr) throws Exception {
         InputStream is = new BufferedInputStream(new FileInputStream(source));
-        return getTagTree(is, ignoreAttr);
+        return getTagTree(is, ignoreAttr, null);
     }
-    public static Tag getTagTree(final InputStream is, final List<String> ignoreAttr) throws Exception {
+    public static Tag getTagTree(final File source,
+                                 final List<String> ignoreAttr,
+                                 Map<QName, Set<String>> types) throws Exception {
+        InputStream is = new BufferedInputStream(new FileInputStream(source));
+        return getTagTree(is, ignoreAttr, types);        
+    }    
+    public static Tag getTagTree(final InputStream is,
+                                 final List<String> ignoreAttr,
+                                 Map<QName, Set<String>> types) throws Exception {
         Tag root = new Tag();
         root.setName(new QName("root", "root"));
 
@@ -123,25 +134,25 @@ public final class ToolsStaxUtils {
                 }
 
                 for (int i = 0; i < reader.getAttributeCount(); i++) {
-                    if ("type".equals(reader.getAttributeLocalName(i))
-                        && "element".equals(reader.getLocalName())) {
-                        //probably a qname to a type, pull namespace in differently
-                        String tp = reader.getAttributeValue(i);
-                        if (tp.contains(":")) {
-                            String ns = tp.substring(0, tp.indexOf(":"));
-                            if ("tns".equals(ns)) {
-                                tp = tp.substring(tp.indexOf(":") + 1);
-                            } else {
-                                ns = reader.getNamespaceURI(ns);
-                                tp = "{" + ns + "}" + tp.substring(tp.indexOf(":") + 1);
+                    //probably a qname to a type, pull namespace in differently
+                    String tp = reader.getAttributeValue(i);
+                    if (isType(types, reader.getName(), reader.getAttributeName(i))) {
+                        int idx = tp.indexOf(':');
+                        if (idx > 0 && tp.length() > idx && tp.substring(idx + 1).indexOf(':') == -1) {
+                            String pfx = tp.substring(0, idx);
+                            String ns = reader.getNamespaceURI(pfx);
+                            if (ns != null) {
+                                tp = "{" + ns + "}" + tp.substring(idx + 1);
+                            }
+                        } else { 
+                            String ns = reader.getNamespaceURI("");
+                            if (ns != null) {
+                                tp = "{" + ns + "}" + tp.substring(idx + 1);
                             }
                         }
-                        newTag.getAttributes().put(reader.getAttributeName(i), 
-                                                   tp);
-                    } else {
-                        newTag.getAttributes().put(reader.getAttributeName(i), 
-                                                   reader.getAttributeValue(i));
                     }
+                    newTag.getAttributes().put(reader.getAttributeName(i), 
+                                               tp);
                 }
 
                 newTag.setParent(currentTag);
@@ -160,8 +171,12 @@ public final class ToolsStaxUtils {
         return root;
     }
 
-    public Tag getLastTag(Tag tag) {
-        int lastIndex = tag.getTags().size() - 1;
-        return tag.getTags().get(lastIndex);
+    private static boolean isType(Map<QName, Set<String>> types, QName name, QName attributeName) {
+        if (types == null) {
+            return false;
+        }
+        Set<String> a = types.get(name);
+        return a != null && a.contains(attributeName.getLocalPart());
     }
-}
+
+}
\ No newline at end of file

Modified: cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/IDLToWSDLGenerationTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/IDLToWSDLGenerationTest.java?rev=1503382&r1=1503381&r2=1503382&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/IDLToWSDLGenerationTest.java (original)
+++ cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/IDLToWSDLGenerationTest.java Mon Jul 15 18:04:20 2013
@@ -34,11 +34,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.namespace.QName;
 
+import org.apache.cxf.binding.corba.wsdl.CorbaConstants;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.corba.common.ProcessorEnvironment;
 import org.apache.cxf.tools.corba.common.ToolCorbaConstants;
 import org.apache.cxf.tools.corba.processors.idl.IDLToWSDLProcessor;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -51,6 +54,28 @@ public class IDLToWSDLGenerationTest ext
 
     @Before
     public void setUp() {
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "anonarray"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "struct"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "member"), "idltype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "object"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "object"), "binding");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "enum"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "union"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "unionbranch"), "idltype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "anonstring"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "anonwstring"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "exception"), "idltype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "exception"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "fixed"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "const"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "const"), "idltype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "array"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "array"), "elemtype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "alias"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "alias"), "basetype");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "anonsequence"), "type");
+        addQNameAttribute(new QName(CorbaConstants.NU_WSDL_CORBA, "anonsequence"), "elemtype");
+
     }
 
     @After
@@ -74,6 +99,7 @@ public class IDLToWSDLGenerationTest ext
         InputStream origStream = getClass().getResourceAsStream(expectedWsdlFilename);  
         InputStream actualStream = new ByteArrayInputStream(out.toString().getBytes());
 
+        System.out.println(out.toString());
         assertWsdlEquals(origStream, actualStream, DEFAULT_IGNORE_ATTR, DEFAULT_IGNORE_TAG);
     }
     

Modified: cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/WSDLToCorbaBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/WSDLToCorbaBindingTest.java?rev=1503382&r1=1503381&r2=1503382&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/WSDLToCorbaBindingTest.java (original)
+++ cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/processors/WSDLToCorbaBindingTest.java Mon Jul 15 18:04:20 2013
@@ -49,6 +49,7 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.tools.corba.common.WSDLCorbaFactory;
 import org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaBinding;
 import org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction;
+
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -506,7 +507,6 @@ public class WSDLToCorbaBindingTest exte
 
         Definition model = generator.generateCORBABinding();
         Document document = writer.getDocument(model);        
-
         Element typemap = getElementNode(document, "corba:typeMapping"); 
         assertNotNull(typemap);        
         assertEquals(1, typemap.getElementsByTagName("corba:enum").getLength());        

Modified: cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/utils/WSDLGenerationTester.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/utils/WSDLGenerationTester.java?rev=1503382&r1=1503381&r2=1503382&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/utils/WSDLGenerationTester.java (original)
+++ cxf/branches/2.6.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/utils/WSDLGenerationTester.java Mon Jul 15 18:04:20 2013
@@ -103,11 +103,19 @@ public class WSDLGenerationTester {
                 //skip this atribute
                 origAttrCount--;
             } else {
+                String s1 = orig.getAttributeValue(origAttrName.getNamespaceURI(),
+                                                   origAttrName.getLocalPart());
+                String s2 = actual.getAttributeValue(origAttrName.getNamespaceURI(),
+                                                     origAttrName.getLocalPart());
+                
+                if (!s1.equals(s2)
+                    && (s1.contains(":") || s2.contains(":"))) {
+                    s1 = mapToQName(orig, s1);
+                    s2 = mapToQName(actual, s2);
+                }
+                
                 Assert.assertEquals("Attribute " + origAttrName + " not found or value not matching",
-                                    orig.getAttributeValue(origAttrName.getNamespaceURI(),
-                                    origAttrName.getLocalPart()),
-                                    actual.getAttributeValue(origAttrName.getNamespaceURI(),
-                                    origAttrName.getLocalPart()));
+                                    s1, s2);
             }
         }
         for (int i = 0; i < actualAttrCount; i++) {
@@ -123,6 +131,22 @@ public class WSDLGenerationTester {
                             actualAttrCount);
     }
 
+    private String mapToQName(XMLStreamReader reader, String s2) {
+        int idx = s2.indexOf(':');
+        String ns = null;
+        if (idx == -1) {
+            ns = reader.getNamespaceURI("");
+        } else {
+            ns = reader.getNamespaceURI(s2.substring(0, idx));
+            if (ns == null) {
+                ns = reader.getNamespaceURI("");
+            } else {
+                s2 = s2.substring(idx + 1);
+            }
+        }
+        return new QName(ns, s2).toString();
+    }
+
     private void compareEndElement(XMLStreamReader orig, XMLStreamReader actual)
         throws Exception {
         Assert.assertEquals("End element is not matched", orig.getName(), actual.getName());