You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/08/01 19:57:29 UTC

svn commit: r681765 - in /servicemix/smx3/branches/servicemix-3.2: ./ common/servicemix-soap2/ common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/ common/ser...

Author: gertv
Date: Fri Aug  1 10:57:28 2008
New Revision: 681765

URL: http://svn.apache.org/viewvc?rev=681765&view=rev
Log:
SM-819: Applying the same solution to the SOAP2 StaxSource

Added:
    servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/
    servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/
    servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/StaxSourceTest.java
Modified:
    servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/pom.xml
    servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java
    servicemix/smx3/branches/servicemix-3.2/pom.xml

Modified: servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/pom.xml?rev=681765&r1=681764&r2=681765&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/pom.xml (original)
+++ servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/pom.xml Fri Aug  1 10:57:28 2008
@@ -86,6 +86,11 @@
           </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <scope>test</scope>
+    </dependency> 
   </dependencies>
 
   <build>

Modified: servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java?rev=681765&r1=681764&r2=681765&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java Fri Aug  1 10:57:28 2008
@@ -108,7 +108,7 @@
                     String localName = streamReader.getLocalName();
                     String prefix = streamReader.getPrefix();
                     String qname = prefix != null && prefix.length() > 0 ? prefix + ":" + localName : localName;
-                    contentHandler.startElement(uri, localName, qname, getAttributes());
+                    contentHandler.startElement(uri == null ? "" : uri, localName, qname, getAttributes());
                     break;
                 }
                 }
@@ -174,7 +174,7 @@
             if (value == null) {
                 value = "";
             }
-            attrs.addAttribute(uri, localName, qName, type, value);
+            attrs.addAttribute(uri == null ? "" : uri, localName, qName, type, value);
         }
         return attrs;
     }

Added: servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/StaxSourceTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/StaxSourceTest.java?rev=681765&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/StaxSourceTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/common/servicemix-soap2/src/test/java/org/apache/servicemix/soap/util/stax/StaxSourceTest.java Fri Aug  1 10:57:28 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+
+/**
+ * Test case for {@link StaxSource}
+ */
+public class StaxSourceTest extends TestCase {
+    
+    private static final String XML = "<test id='001'>contents</test>";
+    private StaxSource source;
+    private Mockery context;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        source = new StaxSource(StaxUtil.createReader(new StringSource(XML)));
+        context = new Mockery();
+    }
+    
+    public void testNoNullUris() throws Exception {
+        final ContentHandler handler = context.mock(ContentHandler.class);
+        source.setContentHandler(handler);
+        context.checking(new Expectations() {{
+           one(handler).startDocument();
+           one(handler).startElement(with(""), with("test"), with("test"), with(noNullUris()));
+           allowing(anything());
+        }});
+        source.parse();
+    }
+    
+    @Factory
+    private static Matcher<Attributes> noNullUris() {
+        return new TypeSafeMatcher<Attributes>() {
+
+            @Override
+            public boolean matchesSafely(Attributes attributes) {
+                //not sure why I need the fail here, returning false should be sufficient
+                if (attributes.getURI(0) == null) {
+                    fail("URI should not be null, but an empty string");
+                }
+                return attributes.getURI(0) != null;
+            }
+            
+            public void describeTo(Description description) {
+                description.appendText("Attributes URI matches empty String");
+            }
+        };
+    }
+}

Modified: servicemix/smx3/branches/servicemix-3.2/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/pom.xml?rev=681765&r1=681764&r2=681765&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/pom.xml (original)
+++ servicemix/smx3/branches/servicemix-3.2/pom.xml Fri Aug  1 10:57:28 2008
@@ -1952,6 +1952,11 @@
                     </exclusion>
                 </exclusions>
             </dependency>
+            <dependency>
+               <groupId>org.jmock</groupId>
+               <artifactId>jmock</artifactId>
+               <version>2.5.0</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
@@ -1993,7 +1998,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.4.3</version>
+                    <version>2.4.2</version>
                     <configuration>
                         <useFile>true</useFile>
                         <forkMode>once</forkMode>