You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/02/09 08:09:30 UTC

svn commit: r1068768 - /commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java

Author: simonetripodi
Date: Wed Feb  9 07:09:30 2011
New Revision: 1068768

URL: http://svn.apache.org/viewvc?rev=1068768&view=rev
Log:
first checkin of NamespaceSnapshotTestCase, adapted versions of the proper on /trunk
old testcases continue pass!

Added:
    commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java   (with props)

Added: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java?rev=1068768&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java (added)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java Wed Feb  9 07:09:30 2011
@@ -0,0 +1,118 @@
+/* $Id$
+ *
+ * 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.commons.digester3;
+
+import static org.apache.commons.digester3.DigesterLoader.newLoader;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.xml.sax.Attributes;
+
+/**
+ * Tests namespace snapshotting.
+ */
+public class NamespaceSnapshotTestCase extends AbstractTestCase {
+
+    /**
+     * A test case specific helper rule.
+     */
+    static class NamespaceSnapshotRule extends Rule {
+        /**
+         * @see Rule#begin(String, String, Attributes)
+         */
+        @Override
+        public final void begin(final String namespace, final String name, final Attributes attributes) {
+            Digester d = getDigester();
+            Map<String, String> namespaces = d.getCurrentNamespaces();
+            ((NamespacedBox) d.peek()).setNamespaces(namespaces);
+        }
+    }
+
+    /**
+     * Namespace snapshot test case.
+     */
+    @Test
+    public void testNamespaceSnapshots() throws Exception {
+        Digester digester = newLoader(new AbstractRulesModule() {
+
+            @Override
+            protected void configure() {
+                forPattern("box")
+                    .createObject().ofType(NamespacedBox.class)
+                    .then()
+                    .setProperties()
+                    .then()
+                    .addRule(new NamespaceSnapshotRule());
+
+                forPattern("box/subBox")
+                    .createObject().ofType(NamespacedBox.class)
+                    .then()
+                    .setProperties()
+                    .then()
+                    .addRule(new NamespaceSnapshotRule())
+                    .then()
+                    .setNext("addChild");
+            }
+
+        })
+        .setNamespaceAware(true)
+        .newDigester();
+
+        Object result = digester.parse(getInputStream("Test11.xml"));
+        assertNotNull(result);
+
+        NamespacedBox root = (NamespacedBox) result;
+        Map<String, String> nsmap = root.getNamespaces();
+        assertEquals(3, nsmap.size());
+        assertEquals("", nsmap.get(""));
+        assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo"));
+        assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
+
+        List<Box> children = root.getChildren();
+        assertEquals(3, children.size());
+
+        NamespacedBox child1 = (NamespacedBox) children.get(0);
+        nsmap = child1.getNamespaces();
+        assertEquals(3, nsmap.size());
+        assertEquals("", nsmap.get(""));
+        assertEquals("http://commons.apache.org/digester/Foo1", nsmap.get("foo"));
+        assertEquals("http://commons.apache.org/digester/Bar1", nsmap.get("bar"));
+
+        NamespacedBox child2 = (NamespacedBox) children.get(1);
+        nsmap = child2.getNamespaces();
+        assertEquals(5, nsmap.size());
+        assertEquals("", nsmap.get(""));
+        assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo"));
+        assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
+        assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha"));
+        assertEquals("http://commons.apache.org/digester/Beta", nsmap.get("beta"));
+
+        NamespacedBox child3 = (NamespacedBox) children.get(2);
+        nsmap = child3.getNamespaces();
+        assertEquals(4, nsmap.size());
+        assertEquals("", nsmap.get(""));
+        assertEquals("http://commons.apache.org/digester/Foo3", nsmap.get("foo"));
+        assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha"));
+        assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain