You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ch...@apache.org on 2006/07/26 07:17:41 UTC
svn commit: r425632 -
/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java
Author: chinthaka
Date: Tue Jul 25 22:17:41 2006
New Revision: 425632
URL: http://svn.apache.org/viewvc?rev=425632&view=rev
Log:
Adding a test case to invalidate the bug mentioned in http://issues.apache.org/jira/browse/WSCOMMONS-12
Modified:
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java
Modified: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java?rev=425632&r1=425631&r2=425632&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java (original)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/IteratorTest.java Tue Jul 25 22:17:41 2006
@@ -16,11 +16,17 @@
package org.apache.axiom.om;
+import org.apache.axiom.attachments.utils.ImageDataSource;
+import org.apache.axiom.attachments.utils.ImageIO;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
+import javax.activation.DataHandler;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
+import java.awt.*;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.FileReader;
import java.util.Iterator;
@@ -55,9 +61,9 @@
int counter = 0;
while (iter.hasNext()) {
counter ++;
- assertNotNull("Must return not null objects!",iter.next());
+ assertNotNull("Must return not null objects!", iter.next());
}
- assertEquals("This element should contain only five children including the text ",5,counter);
+ assertEquals("This element should contain only five children including the text ", 5, counter);
}
/**
@@ -70,10 +76,10 @@
while (iter.hasNext()) {
counter ++;
Object o = iter.next();
- assertNotNull("Must return not null objects!",o);
- assertTrue("All these should be elements!",((OMNode)o).getType()==OMNode.ELEMENT_NODE);
+ assertNotNull("Must return not null objects!", o);
+ assertTrue("All these should be elements!", ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
}
- assertEquals("This element should contain only two elements ",2,counter);
+ assertEquals("This element should contain only two elements ", 2, counter);
}
/**
@@ -81,16 +87,16 @@
*/
public void testElementQNameIterator() {
OMElement elt = envelope;
- QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/","body");
+ QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "body");
Iterator iter = elt.getChildrenWithName(qname);
int counter = 0;
while (iter.hasNext()) {
counter ++;
Object o = iter.next();
- assertNotNull("Must return not null objects!",o);
- assertTrue("All these should be elements!",((OMNode)o).getType()==OMNode.ELEMENT_NODE);
+ assertNotNull("Must return not null objects!", o);
+ assertTrue("All these should be elements!", ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
}
- assertEquals("This element should contain only one element with the given QName ",1,counter);
+ assertEquals("This element should contain only one element with the given QName ", 1, counter);
}
/**
@@ -178,6 +184,95 @@
firstChildrenCount - 1,
secondChildrenCount);
+ }
+
+ /**
+ * This will test the errrors mentioned in @link http://issues.apache.org/jira/browse/WSCOMMONS-12
+ */
+ public void testScenariosInJIRA() {
+ try {
+ OMElement mtomSampleElement = createSampleXMLForTesting();
+ testScenarioOne(mtomSampleElement);
+ testScenarioTwo(mtomSampleElement);
+
+
+ } catch (Exception e) {
+ fail("Exception occurred whilst running the test " + e);
+ }
+
+ }
+
+ private OMElement createSampleXMLForTesting() throws Exception {
+ try {
+ File imageSource = new File("test-resources/mtom/img/test.jpg");
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+
+ OMElement data = fac.createOMElement("mtomSample", omNs);
+ OMElement image = fac.createOMElement("image", omNs);
+ Image expectedImage;
+ expectedImage = new ImageIO()
+ .loadImage(new FileInputStream(imageSource));
+
+ ImageDataSource dataSource = new ImageDataSource("test.jpg",
+ expectedImage);
+ DataHandler expectedDH = new DataHandler(dataSource);
+ OMText textData = fac.createOMText(expectedDH, true);
+ image.addChild(textData);
+
+ OMElement imageName = fac.createOMElement("fileName", omNs);
+ if (imageSource != null) {
+ imageName.setText(imageSource.getAbsolutePath());
+ }
+ data.addChild(image);
+ data.addChild(imageName);
+
+ return data;
+ } catch (Exception e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ return null;
+ }
+
+ private void testScenarioOne(OMElement mtomSampleElement) {
+ Iterator imageElementIter = mtomSampleElement.getChildrenWithName(new QName("image"));
+ // do something with the iterator
+ while (imageElementIter.hasNext()) {
+ OMNode omNode = (OMNode) imageElementIter.next();
+ // do nothing
+ }
+
+ Iterator fileNameElementIter = mtomSampleElement.getChildrenWithName(new QName("fileName"));
+ // do something with the iterator
+ while (fileNameElementIter.hasNext()) {
+ OMNode omNode = (OMNode) fileNameElementIter.next();
+ if (omNode instanceof OMElement) {
+ OMElement fileNameElement = (OMElement) omNode;
+ assertTrue("fileName".equalsIgnoreCase(fileNameElement.getLocalName()));
+ }
+ }
+ }
+
+ private void testScenarioTwo(OMElement mtomSampleElement) {
+ Iterator childElementsIter = mtomSampleElement.getChildElements();
+
+ boolean imageElementFound = false;
+ boolean fileNameElementFound = false;
+
+ while (childElementsIter.hasNext()) {
+ OMNode omNode = (OMNode) childElementsIter.next();
+ if (omNode instanceof OMElement) {
+ OMElement omElement = (OMElement) omNode;
+ if (omElement.getLocalName().equals("fileName")) {
+ fileNameElementFound = true;
+ } else if (omElement.getLocalName().equals("image")) {
+ imageElementFound = true;
+ }
+ }
+ }
+
+ assertTrue(fileNameElementFound && imageElementFound);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org