You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/06/24 22:18:56 UTC

svn commit: r671330 [4/4] - in /servicemix/smx3/trunk/core: ./ servicemix-core/ servicemix-core/src/main/java/org/apache/servicemix/expression/ servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/ servicemix-core/src/main/java/org/apache/servi...

Added: servicemix/smx3/trunk/core/servicemix-utils/src/test/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReaderTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-utils/src/test/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReaderTest.java?rev=671330&view=auto
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-utils/src/test/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReaderTest.java (added)
+++ servicemix/smx3/trunk/core/servicemix-utils/src/test/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReaderTest.java Tue Jun 24 13:18:54 2008
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.jaxp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * @since Oct 26, 2004
+ */
+public class W3CDOMStreamReaderTest extends AbstractStreamReaderTest {
+
+    private static final Log LOG = LogFactory.getLog(W3CDOMStreamReaderTest.class);
+
+    public void testSingleElement() throws Exception {
+        Document doc = getDocument();
+        Element e = doc.createElementNS("urn:test", "root");
+        e.setAttribute("xmlns", "urn:test");
+        doc.appendChild(e);
+
+        assertEquals(1, e.getAttributes().getLength());
+        LOG.info("start: " + XMLStreamReader.START_ELEMENT);
+        LOG.info("attr: " + XMLStreamReader.ATTRIBUTE);
+        LOG.info("ns: " + XMLStreamReader.NAMESPACE);
+        LOG.info("chars: " + XMLStreamReader.CHARACTERS);
+        LOG.info("end: " + XMLStreamReader.END_ELEMENT);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        writeXml(doc, baos);
+        LOG.info(baos.toString());
+        W3CDOMStreamReader reader = new W3CDOMStreamReader(doc.getDocumentElement());
+        testSingleElement(reader);
+    }
+
+    private Document getDocument() throws Exception {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory.newDocumentBuilder().newDocument();
+    }
+
+    public void testTextChild() throws Exception {
+        Document doc = getDocument();
+        Element e = doc.createElementNS("urn:test", "root");
+        e.setAttribute("xmlns", "urn:test");
+        doc.appendChild(e);
+        Node text = doc.createTextNode("Hello World");
+        e.appendChild(text);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        writeXml(doc, baos);
+        LOG.info(baos.toString());
+
+        W3CDOMStreamReader reader = new W3CDOMStreamReader(e);
+        testTextChild(reader);
+    }
+
+    public void testMixedContent() throws Exception {
+        Document doc = getDocument();
+        Element e = doc.createElementNS("urn:test", "test:root");
+        e.setAttribute("xmlns", "urn:test");
+        doc.appendChild(e);
+        Node text = doc.createTextNode("Hello World");
+        e.appendChild(text);
+        Element child = doc.createElement("element");
+        e.appendChild(child);
+        text = doc.createTextNode(" more text");
+        e.appendChild(text);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        writeXml(doc, baos);
+        LOG.info(baos);
+
+        W3CDOMStreamReader reader = new W3CDOMStreamReader(e);
+        testMixedContent(reader);
+    }
+
+    public void testAttributes() throws Exception {
+        Document doc = getDocument();
+
+        Element e = doc.createElementNS("urn:test", "root");
+        e.setAttribute("xmlns", "urn:test");
+        doc.appendChild(e);
+        e.setAttribute("att1", "value1");
+
+        Attr attr = doc.createAttributeNS("urn:test2", "att2");
+        attr.setValue("value2");
+        attr.setPrefix("p");
+
+        e.setAttribute("xmlns:p", "urn:test2");
+
+        e.setAttributeNode(attr);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        writeXml(doc, baos);
+        LOG.info(baos.toString());
+
+        W3CDOMStreamReader reader = new W3CDOMStreamReader(doc.getDocumentElement());
+
+        testAttributes(reader);
+    }
+
+    public void testElementChild() throws Exception {
+        Document doc = getDocument();
+        Element e = doc.createElementNS("urn:test", "root");
+        e.setAttribute("xmlns", "urn:test");
+        Element child = doc.createElementNS("urn:test2", "child");
+        child.setAttribute("xmlns:a", "urn:test2");
+
+        child.setPrefix("a");
+        e.appendChild(child);
+        doc.appendChild(e);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        writeXml(doc, baos);
+        LOG.info(baos.toString());
+
+        W3CDOMStreamReader reader = new W3CDOMStreamReader(e);
+        testElementChild(reader);
+    }
+
+    protected void writeXml(Document doc, OutputStream out) throws TransformerException {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        // identity
+        Transformer t = tf.newTransformer();
+        t.setOutputProperty(OutputKeys.INDENT, "yes");
+        t.transform(new DOMSource(doc), new StreamResult(out));
+    }
+}

Added: servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/expression/expression-editor.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/expression/expression-editor.xml?rev=671330&view=auto
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/expression/expression-editor.xml (added)
+++ servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/expression/expression-editor.xml Tue Jun 24 13:18:54 2008
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+	<bean id="ExpressionTestSupport" class="org.apache.servicemix.expression.ExpressionTestSupport">
+		<property name="expression"><value>test</value></property>
+	</bean>
+</beans>

Added: servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/jbi/jaxp/test.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/jbi/jaxp/test.xml?rev=671330&view=auto
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/jbi/jaxp/test.xml (added)
+++ servicemix/smx3/trunk/core/servicemix-utils/src/test/resources/org/apache/servicemix/jbi/jaxp/test.xml Tue Jun 24 13:18:54 2008
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<test firstAtt="toto" secondAtt="titit" xmlns:u="uri:test3">
+  <u:hello u:id="3">world</u:hello>
+  <!-- A comment -->
+  <child xmlns="uri:test" atr1="val1" xmlns:t="uri:test2" t:atr2="val2">
+    <child2> t i u </child2>
+    <child3 xmlns=""/>
+  </child>
+  <child4>   </child4>
+  <long>00 01 02 03 04 05 06 07 08 09
+10 11 12 13 14 15 16 17 18 19
+20 21 22 23 24 25 26 27 28 29
+30 31 32 33 34 35 36 37 38 39
+40 41 42 43 44 45 46 47 48 49
+50 51 52 53 54 55 56 57 58 59
+60 61 62 63 64 65 66 67 68 69
+70 71 72 73 74 75 76 77 78 79
+80 81 82 83 84 85 86 87 88 89
+90 91 92 93 94 95 96 97 98 99
+00 01 02 03 04 05 06 07 08 09
+10 11 12 13 14 15 16 17 18 19
+20 21 22 23 24 25 26 27 28 29
+30 31 32 33 34 35 36 37 38 39
+40 41 42 43 44 45 46 47 48 49
+50 51 52 53 54 55 56 57 58 59
+60 61 62 63 64 65 66 67 68 69
+70 71 72 73 74 75 76 77 78 79
+80 81 82 83 84 85 86 87 88 89
+90 91 92 93 94 95 96 97 98 99
+00 01 02 03 04 05 06 07 08 09
+10 11 12 13 14 15 16 17 18 19
+20 21 22 23 24 25 26 27 28 29
+30 31 32 33 34 35 36 37 38 39
+40 41 42 43 44 45 46 47 48 49
+50 51 52 53 54 55 56 57 58 59
+60 61 62 63 64 65 66 67 68 69
+70 71 72 73 74 75 76 77 78 79
+80 81 82 83 84 85 86 87 88 89
+90 91 92 93 94 95 96 97 98 99
+00 01 02 03 04 05 06 07 08 09
+10 11 12 13 14 15 16 17 18 19
+20 21 22 23 24 25 26 27 28 29
+30 31 32 33 34 35 36 37 38 39
+40 41 42 43 44 45 46 47 48 49
+50 51 52 53 54 55 56 57 58 59
+60 61 62 63 64 65 66 67 68 69
+70 71 72 73 74 75 76 77 78 79
+80 81 82 83 84 85 86 87 88 89
+90 91 92 93 94 95 96 97 98 99
+</long>
+</test>