You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/11/07 00:43:11 UTC
svn commit: r1198594 [1/2] - in
/webservices/commons/trunk/modules/axiom/modules:
axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/
axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/
axiom-testsuite/src/main/java/org/apache/axiom/ts/ axiom-...
Author: veithen
Date: Sun Nov 6 23:43:10 2011
New Revision: 1198594
URL: http://svn.apache.org/viewvc?rev=1198594&view=rev
Log:
AXIOM-311: Refactored OMSourcedElementTest.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeAndConsumeToStream.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeAndConsumeToWriter.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeAndConsumeToXMLWriter.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeAndConsumeToXMLWriterEmbedded.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeModifiedOMSEWithNonDestructiveDataSource.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToStream.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToWriter.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToXMLWriter.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToXMLWriterEmbedded.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToXMLWriterFromReader.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSerializeToXMLWriterFromReaderEmbedded.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSourceOnAlreadyExpandedElement.java (with props)
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Added: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.axiom.om.impl.llom;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class OMSourcedElementTest extends TestCase {
+ /** Ensure that each method of OMElementImpl is overridden in OMSourcedElementImpl */
+ public void testMethodOverrides() {
+ Method[] submeths = OMSourcedElementImpl.class.getDeclaredMethods();
+ Method[] supmeths = OMElementImpl.class.getDeclaredMethods();
+ outer:
+ for (int i = 0; i < supmeths.length; i++) {
+ Method supmeth = supmeths[i];
+ Class[] params = supmeth.getParameterTypes();
+ if (!Modifier.isPrivate(supmeth.getModifiers())) {
+ for (int j = 0; j < submeths.length; j++) {
+ Method submeth = submeths[j];
+ if (supmeth.getName().equals(submeth.getName())) {
+ if (Arrays.equals(params, submeth.getParameterTypes())) {
+ continue outer;
+ }
+ }
+ }
+ fail("OMSourcedElementImpl must override method " + supmeth +
+ "\nSee class JavaDocs for details");
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1198594&r1=1198593&r2=1198594&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Sun Nov 6 23:43:10 2011
@@ -264,7 +264,33 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnOrphan(metaFactory));
addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnSelf(metaFactory));
if (supportsOMSourcedElement) {
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestComplete(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestExpand(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1DefaultPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1QualifiedPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1Unqualified(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName2DefaultPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName2QualifiedPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName2Unqualified(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName3DefaultPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName3QualifiedPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName3Unqualified(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName4DefaultPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName4QualifiedPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestName4Unqualified(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeAndConsumeToStream(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeAndConsumeToWriter(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeAndConsumeToXMLWriter(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeAndConsumeToXMLWriterEmbedded(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeModifiedOMSEWithNonDestructiveDataSource(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToStream(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToWriter(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriter(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterEmbedded(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterFromReader(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterFromReaderEmbedded(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSetDataSourceOnAlreadyExpandedElement(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
}
addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/** Tests the characteristics of OMSourcedElementImpl. */
+public abstract class OMSourcedElementTest extends AxiomTestCase {
+ protected static String testDocument =
+ "<library xmlns=\"http://www.sosnoski.com/uwjws/library\" books=\"1\">" +
+ "<type id=\"java\" category=\"professional\" deductable=\"true\">" +
+ "<name>Java Reference</name></type><type id=\"xml\" " +
+ "category=\"professional\" deductable=\"true\"><name>XML Reference</name>" +
+ "</type><book isbn=\"1930110111\" type=\"xml\"><title>XSLT Quickly</title>" +
+ "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
+ "<price>29.95</price></book></library>";
+
+ // Same as testDocument except that an non-default prefix is used
+ protected static String testDocument2 =
+ "<pre:library xmlns:pre=\"http://www.sosnoski.com/uwjws/library\" books=\"1\">" +
+ "<pre:type id=\"java\" category=\"professional\" deductable=\"true\">" +
+ "<pre:name>Java Reference</pre:name></pre:type><pre:type id=\"xml\" " +
+ "category=\"professional\" deductable=\"true\"><pre:name>XML Reference</pre:name>" +
+ "</pre:type><pre:book isbn=\"1930110111\" type=\"xml\"><pre:title>XSLT Quickly</pre:title>" +
+ "<pre:author>DuCharme, Bob</pre:author><pre:publisher>Manning</pre:publisher>" +
+ "<pre:price>29.95</pre:price></pre:book></pre:library>";
+
+ // Same as testDocument exception that the elements are unqualified
+ protected static String testDocument3 =
+ "<library books=\"1\">" +
+ "<type id=\"java\" category=\"professional\" deductable=\"true\">" +
+ "<name>Java Reference</name></type><type id=\"xml\" " +
+ "category=\"professional\" deductable=\"true\"><name>XML Reference</name>" +
+ "</type><book isbn=\"1930110111\" type=\"xml\"><title>XSLT Quickly</title>" +
+ "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
+ "<price>29.95</price></book></library>";
+
+ protected OMSourcedElement element;
+ protected OMElement root;
+
+ public OMSourcedElementTest(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void setUp() throws Exception {
+ OMFactory f = metaFactory.getOMFactory();
+ OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ element = f.createOMElement(new TestDataSource(testDocument), "library", ns);
+ root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+ }
+}
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,68 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+
+/**
+ * Make sure that the incomplete setting of an OMSE is not
+ * propogated to the root
+ **/
+public class TestComplete extends OMSourcedElementTest {
+ public TestComplete(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // Build a root element and child OMSE
+ OMFactory f = metaFactory.getOMFactory();
+ OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMElement child = f.createOMElement(new TestDataSource(testDocument), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+
+ // Trigger expansion of the child OMSE
+ // This will cause the child to be partially parsed (i.e. incomplete)
+ child.getChildren();
+
+ // Add the child OMSE to the root.
+ root.addChild(child);
+
+ // Normally adding an incomplete child to a parent will
+ // cause the parent to be marked as incomplete.
+ // But OMSE's are self-contained...therefore the root
+ // should still be complete
+ assertTrue(!child.isComplete());
+ assertTrue(root.isComplete());
+
+ // Now repeat the test, but this time trigger the
+ // partial parsing of the child after adding it to the root.
+ child = f.createOMElement(new TestDataSource(testDocument), "library", ns);
+ root = f.createOMElement("root", rootNS);
+
+ root.addChild(child);
+ child.getChildren(); // causes partial parsing...i.e. incomplete child
+
+ assertTrue(!child.isComplete());
+ assertTrue(root.isComplete());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestComplete.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2009-2011 Andreas Veithen
+ *
+ * Licensed 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.axiom.ts.om.sourcedelement;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.io.Writer;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.StAXUtils;
+
+class TestDataSource implements OMDataSource {
+ // The data source is a ByteArrayInputStream so that we can verify that the datasource
+ // is only accessed once. Currently there is no way to identify a destructive vs. non-destructive OMDataSource.
+ private final ByteArrayInputStream data;
+
+ TestDataSource(String data) {
+ this.data = new ByteArrayInputStream(data.getBytes());
+ this.data.mark(0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axiom.om.OMDataSource#serialize(java.io.OutputStream, org.apache.axiom.om.OMOutputFormat)
+ */
+ public void serialize(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ try {
+ output.write(getBytes());
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axiom.om.OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
+ */
+ public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+ try {
+ writer.write(getString());
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axiom.om.OMDataSource#serialize(javax.xml.stream.XMLStreamWriter)
+ */
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(getReader(), xmlWriter);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axiom.om.OMDataSource#getReader()
+ */
+ public XMLStreamReader getReader() throws XMLStreamException {
+ return StAXUtils.createXMLStreamReader(new StringReader(getString()));
+ }
+
+ private byte[] getBytes() throws XMLStreamException {
+ try {
+ // The data from the data source should only be accessed once
+ //data.reset();
+ byte[] rc = new byte[data.available()];
+ data.read(rc);
+ return rc;
+ } catch (IOException io) {
+ throw new XMLStreamException(io);
+ }
+ }
+
+ private String getString() throws XMLStreamException {
+ String text = new String(getBytes());
+ return text;
+ }
+}
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+
+/**
+ * Make sure the expanded OMSourcedElement behaves like a normal OMElement.
+ */
+public class TestExpand extends OMSourcedElementTest {
+ public TestExpand(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ element.getAllDeclaredNamespaces();
+ assertEquals("Expanded namespace count error", 1,
+ countItems(element.getAllDeclaredNamespaces()));
+ assertEquals("Expanded attribute count error", 1,
+ countItems(element.getAllAttributes()));
+ assertEquals("Expanded attribute value error", "1",
+ element.getAttributeValue(new QName("books")));
+ OMElement child = element.getFirstElement();
+ assertEquals("Child element name", "type", child.getLocalName());
+ assertEquals("Child element namespace",
+ "http://www.sosnoski.com/uwjws/library",
+ child.getNamespace().getNamespaceURI());
+ OMNode next = child.getNextOMSibling();
+ assertTrue("Expected child element", next instanceof OMElement);
+ next = next.getNextOMSibling();
+ assertTrue("Expected child element", next instanceof OMElement);
+ child = (OMElement) next;
+ assertEquals("Child element name", "book", child.getLocalName());
+ assertEquals("Child element namespace",
+ "http://www.sosnoski.com/uwjws/library",
+ child.getNamespace().getNamespaceURI());
+ assertEquals("Attribute value error", "xml",
+ child.getAttributeValue(new QName("type")));
+ }
+
+ private int countItems(Iterator iter) {
+ int count = 0;
+ while (iter.hasNext()) {
+ count++;
+ iter.next();
+ }
+ return count;
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestExpand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,91 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument (which uses the default namespace) Type of
+ * Serialization: Serialize and cache Prefix test
+ */
+public class TestName1DefaultPrefix extends OMSourcedElementTest {
+ public TestName1DefaultPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns =
+ f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and cache. This should cause expansion. The prefix should be updated to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(element.getDefaultNamespace() != null);
+ assertTrue(result.indexOf("DUMMYPREFIX") <
+ 0); // Make sure that the serialized string does not contain DUMMYPREFIX
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(element.getDefaultNamespace() != null);
+ assertTrue(result.indexOf("DUMMYPREFIX") <
+ 0); // Make sure that the serialized string does not contain DUMMYPREFIX
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1DefaultPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,90 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument2 (which uses a qualified prefix) Type of Serialization:
+ * Serialize and cache Prefix test
+ */
+public class TestName1QualifiedPrefix extends OMSourcedElementTest {
+ public TestName1QualifiedPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument2), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and cache. This should cause expansion and update the name to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals("pre"));
+ assertTrue(element.getDefaultNamespace() == null);
+ assertTrue(result.indexOf("xmlns=") <
+ 0);// Make sure that the serialized string does not contain default prefix declaration
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals("pre"));
+ assertTrue(result.indexOf("xmlns=") <
+ 0); // Make sure that the serialized string does not contain default prefix declaration
+ assertTrue(element.getDefaultNamespace() == null);
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1QualifiedPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,89 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument3 (which uses unqualified names) Type of Serialization:
+ * Serialize and cache Prefix test
+ */
+public class TestName1Unqualified extends OMSourcedElementTest {
+ public TestName1Unqualified(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument3), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and cache. This should cause expansion and update the name to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(element.getDefaultNamespace() == null ||
+ element.getDefaultNamespace().getNamespaceURI().length() == 0);
+ assertTrue(result.indexOf("xmlns=") <
+ 0); // Make sure that the serialized string does not contain default prefix declaration
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("xmlns=") <
+ 0);// Make sure that the serialized string does not contain default prefix declaration
+ assertTrue(element.getDefaultNamespace() == null ||
+ element.getDefaultNamespace().getNamespaceURI().length() == 0);
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java Sun Nov 6 23:43:10 2011
@@ -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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument (which uses the default namespace) Type of
+ * Serialization: Serialize and consume Tests update of prefix
+ */
+public class TestName2DefaultPrefix extends OMSourcedElementTest {
+ public TestName2DefaultPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns =
+ f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+ assertTrue(result.indexOf("DUMMYPREFIX") <
+ 0); // Make sure that the serialized string does not contain DUMMYPREFIX
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2DefaultPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument2 (which uses a qualified prefix) Type of Serialization:
+ * Serialize and consume Tests update of prefix
+ */
+public class TestName2QualifiedPrefix extends OMSourcedElementTest {
+ public TestName2QualifiedPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument2), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("xmlns=") <
+ 0); // Make sure that the serialized string does not contain default prefix declaration
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2QualifiedPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument3 (which uses unqualified names) Type of Serialization:
+ * Serialize and consume Tests update of prefix
+ */
+public class TestName2Unqualified extends OMSourcedElementTest {
+ public TestName2Unqualified(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument3), "library", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("xmlns=") <
+ 0);// Make sure that the serialized string does not contain default prefix declaration
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument (which uses the default namespace) Type of
+ * Serialization: Serialize and cache Tests attempt to rename namespace and localpart, which is
+ * not allowed
+ */
+public class TestName3DefaultPrefix extends OMSourcedElementTest {
+ public TestName3DefaultPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and cache. This should cause expansion and update the name to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+
+ try {
+ root.serialize(writer);
+ } catch (Exception e) {
+ // Current Behavior
+ // The current OMSourceElementImpl ensures that the namespace and localName
+ // are consistent with the original setting.
+ return;
+ }
+
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3DefaultPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument2 (which uses a qualified prefix) Type of Serialization:
+ * Serialize and cache Tests attempt to rename namespace and localpart, which is not allowed
+ */
+public class TestName3QualifiedPrefix extends OMSourcedElementTest {
+ public TestName3QualifiedPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument2), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and cache. This should cause expansion and update the name to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+
+ try {
+ root.serialize(writer);
+ } catch (Exception e) {
+ // Current Behavior
+ // The current OMSourceElementImpl ensures that the namespace and localName
+ // are consistent with the original setting.
+ return;
+ }
+
+
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0);// Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0);// Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3QualifiedPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument3 (which uses unqualified names) Type of Serialization:
+ * Serialize and cache Tests attempt to rename namespace and localpart, which is not allowed
+ */
+public class TestName3Unqualified extends OMSourcedElementTest {
+ public TestName3Unqualified(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument3), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and cache. This should cause expansion and update the name to match the testDocument string
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+
+ try {
+ root.serialize(writer);
+ } catch (Exception e) {
+ // Current Behavior
+ // The current OMSourceElementImpl ensures that the namespace and localName
+ // are consistent with the original setting.
+ return;
+ }
+
+
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+
+ // Serialize again
+ writer = new StringWriter();
+ xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serialize(writer);
+ xmlwriter.flush();
+ result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("library"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals(
+ "http://www.sosnoski.com/uwjws/library"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName3Unqualified.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument (which uses the default namespace) Type of
+ * Serialization: Serialize and consume Tests that the namespace and localName are not affected
+ * by the serializeAndConsume
+ */
+public class TestName4DefaultPrefix extends OMSourcedElementTest {
+ public TestName4DefaultPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "DUMMYPREFIX");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4DefaultPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument2 (which uses a qualified prefix) Type of Serialization:
+ * Serialize and cache Tests attempt to rename namespace and localpart, which is not allowed
+ */
+public class TestName4QualifiedPrefix extends OMSourcedElementTest {
+ public TestName4QualifiedPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument2), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+ assertTrue(result.indexOf("xmlns=") <
+ 0);// Make sure that the serialized string does not contain the default prefix declaration
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4QualifiedPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java?rev=1198594&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java Sun Nov 6 23:43:10 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.axiom.ts.om.sourcedelement;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+
+/**
+ * Tests the OMSourcedElement localName, namespace and prefix settings before and after
+ * serialization Document: testDocument3 (which uses unqualified names) Type of Serialization:
+ * Serialize and cache Tests attempt to rename namespace and localpart, which is not allowed
+ */
+public class TestName4Unqualified extends OMSourcedElementTest {
+ public TestName4Unqualified(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory f = metaFactory.getOMFactory();
+
+ // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+ OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
+ OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "");
+ OMElement element =
+ f.createOMElement(new TestDataSource(testDocument3), "DUMMYNAME", ns);
+ OMElement root = f.createOMElement("root", rootNS);
+ root.addChild(element);
+
+ // Test getting the namespace, localpart and prefix. This should used not result in expansion
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+
+ // Serialize and consume. This should not cause expansion and currently won't update
+ // the name of the element.
+ StringWriter writer = new StringWriter();
+ XMLStreamWriter xmlwriter = StAXUtils.createXMLStreamWriter(writer);
+ root.serializeAndConsume(writer);
+ xmlwriter.flush();
+ String result = writer.toString();
+
+ assertTrue(element.getLocalName().equals("DUMMYNAME"));
+ assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+ assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertTrue(result.indexOf("DUMMY") <
+ 0); // Make sure that the serialized string does not contain the DUMMY values
+ assertTrue(result.indexOf("xmlns=") <
+ 0); // Make sure that the serialized string does not contain the default prefix declaration
+
+ assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName4Unqualified.java
------------------------------------------------------------------------------
svn:eol-style = native