You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by gi...@apache.org on 2011/10/31 12:33:58 UTC

svn commit: r1195420 - in /webservices/wss4j/branches/swssf/streaming-xml-security/src: main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java

Author: giger
Date: Mon Oct 31 11:33:58 2011
New Revision: 1195420

URL: http://svn.apache.org/viewvc?rev=1195420&view=rev
Log:
XMLSecurityEventReader tests and fixes

Added:
    webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java   (with props)
Modified:
    webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java   (contents, props changed)

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java?rev=1195420&r1=1195419&r2=1195420&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java Mon Oct 31 11:33:58 2011
@@ -27,8 +27,8 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
- * @author $Author:$
- * @version $Revision:$ $Date:$
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
 public class XMLSecurityEventReader implements XMLEventReader {
 
@@ -73,28 +73,27 @@ public class XMLSecurityEventReader impl
             return this.nextXMLEvent;
         }
         try {
-            this.nextXMLEvent = xmlEventIterator.next();
+            return this.nextXMLEvent = xmlEventIterator.next();
         } catch (NoSuchElementException e) {
-            throw new XMLStreamException(e);
+            return null;
         }
-        return this.nextXMLEvent;
     }
 
     @Override
     public String getElementText() throws XMLStreamException {
-        //todo
+        //ATM not needed and therefore not implemented
         throw new XMLStreamException(new UnsupportedOperationException());
     }
 
     @Override
     public XMLEvent nextTag() throws XMLStreamException {
-        //todo
+        //ATM not needed and therefore not implemented
         throw new XMLStreamException(new UnsupportedOperationException());
     }
 
     @Override
     public Object getProperty(String name) throws IllegalArgumentException {
-        //todo
+        //ATM not needed and therefore not implemented
         throw new IllegalArgumentException(new UnsupportedOperationException());
     }
 

Propchange: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java?rev=1195420&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java (added)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java Mon Oct 31 11:33:58 2011
@@ -0,0 +1,109 @@
+/**
+ * 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.swssf.xmlsec.test;
+
+import junit.framework.Assert;
+import org.swssf.xmlsec.impl.XMLSecurityEventReader;
+import org.testng.annotations.Test;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.events.XMLEvent;
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class XMLSecurityEventReaderTest {
+
+    @Test
+    public void testConformness() throws Exception {
+        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+        XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml"));
+
+        Deque<XMLEvent> xmlEventDeque = new LinkedList<XMLEvent>();
+        while (xmlEventReader.hasNext()) {
+            XMLEvent xmlEvent = xmlEventReader.nextEvent();
+            xmlEventDeque.push(xmlEvent);
+        }
+
+        XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlEventDeque, 0);
+
+        xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml"));
+        while (xmlEventReader.hasNext()) {
+            Assert.assertEquals(xmlEventReader.hasNext(), xmlSecurityEventReader.hasNext());
+            XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
+            XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
+            Assert.assertEquals(stdXmlEvent.getEventType(), secXmlEvent.getEventType());
+
+            XMLEvent stdPeekedXMLEvent = xmlEventReader.peek();
+            XMLEvent secPeekedXMLEvent = xmlSecurityEventReader.peek();
+            if (stdPeekedXMLEvent == null) {
+                Assert.assertNull(secPeekedXMLEvent);
+            } else {
+                Assert.assertEquals(stdPeekedXMLEvent.getEventType(), secPeekedXMLEvent.getEventType());
+            }
+        }
+
+        Assert.assertFalse(xmlEventReader.hasNext());
+        Assert.assertFalse(xmlSecurityEventReader.hasNext());
+    }
+
+    @Test
+    public void testIndex() throws Exception {
+        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+        XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml"));
+
+        Deque<XMLEvent> xmlEventDeque = new LinkedList<XMLEvent>();
+        while (xmlEventReader.hasNext()) {
+            XMLEvent xmlEvent = xmlEventReader.nextEvent();
+            xmlEventDeque.push(xmlEvent);
+        }
+
+        int skip = 100;
+
+        XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlEventDeque, skip);
+
+        xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml"));
+        int currentIndex = 0;
+        while (xmlEventReader.hasNext()) {
+            XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
+
+            if (currentIndex++ < skip) {
+                continue;
+            }
+
+            XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
+            Assert.assertEquals(stdXmlEvent.getEventType(), secXmlEvent.getEventType());
+
+            XMLEvent stdPeekedXMLEvent = xmlEventReader.peek();
+            XMLEvent secPeekedXMLEvent = xmlSecurityEventReader.peek();
+            if (stdPeekedXMLEvent == null) {
+                Assert.assertNull(secPeekedXMLEvent);
+            } else {
+                Assert.assertEquals(stdPeekedXMLEvent.getEventType(), secPeekedXMLEvent.getEventType());
+            }
+        }
+
+        Assert.assertFalse(xmlEventReader.hasNext());
+        Assert.assertFalse(xmlSecurityEventReader.hasNext());
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-xml-security/src/test/java/org/swssf/xmlsec/test/XMLSecurityEventReaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision