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/15 21:59:06 UTC

svn commit: r1071055 - in /commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules: FromXmlRuleSetTest.java ObjectTestImpl.java

Author: simonetripodi
Date: Tue Feb 15 20:59:06 2011
New Revision: 1071055

URL: http://svn.apache.org/viewvc?rev=1071055&view=rev
Log:
first checkin of FromXmlRuleSetTest, an adapted version of the proper one on /trunk

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

Added: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java?rev=1071055&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java (added)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java Tue Feb 15 20:59:06 2011
@@ -0,0 +1,63 @@
+/* $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.xmlrules;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+
+import org.apache.commons.digester3.AbstractTestCase;
+import org.apache.commons.digester3.Digester;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+/**
+ * Tests loading Digester rules from an XML file.
+ */
+public class FromXmlRuleSetTest extends AbstractTestCase {
+
+    /** 
+     * Test the FromXmlRules.addRuleInstances(digester, path) method, ie
+     * test loading rules at a base position other than the root.
+     */
+    @Test
+    public void testBasePath() throws Exception {
+        String xmlRules =
+            "<?xml version='1.0'?>"
+            + "<digester-rules>"
+            + "   <pattern value='root/foo'>"
+            + "      <call-method-rule methodname='setProperty' usingElementBodyAsArgument='true' />"
+            + "   </pattern>"
+            + "</digester-rules>";
+
+        String xml =
+            "<?xml version='1.0'?>"
+            + "<root>"
+            + "  <foo>success</foo>"
+            + "</root>";
+
+        ObjectTestImpl testObject = new ObjectTestImpl();
+        Digester digester = newBasicDigester(new FromXmlRulesModule(new StringReader(xmlRules)));
+
+        digester.push(testObject);
+        digester.parse(new InputSource(new StringReader(xml)));
+
+        assertEquals("success", testObject.getProperty());
+    }
+
+}

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

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

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

Added: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java?rev=1071055&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java (added)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java Tue Feb 15 20:59:06 2011
@@ -0,0 +1,100 @@
+/* $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.xmlrules;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Test harness object for holding results of digestion.
+ *
+ * @author David H. Martin - Initial Contribution
+ * @author Scott Sanders   - Added ASL, removed external dependencies
+ * @author Tim O'Brien - Added bean property to test bean property setter rule
+ */
+public class ObjectTestImpl {
+
+    private List<Object> children = new ArrayList<Object>();
+
+    private String value = "";
+
+    private Long longValue = new Long(-1L);
+
+    private String property = "";
+
+    private HashMap<String, String> mapValue = new HashMap<String, String>();
+
+    private boolean pushed = false;
+
+    public ObjectTestImpl() {
+    }
+
+    @Override
+    public String toString() {
+        String str = value;
+        for (Object o : children) {
+            str += " " + o;
+        }
+        return str;
+    }
+
+    public void add(Object o) {
+        children.add(o);
+    }
+
+    public void setValue(String val) {
+        value = val;
+    }
+
+    public void setLongValue(Long val) {
+        longValue = val;
+    }
+
+    public Long getLongValue() {
+        return longValue;
+    }
+
+    public void setStringValue(String val) {
+    }
+
+    public boolean isPushed() {
+        return pushed;
+    }
+    
+    public void push() {
+        pushed = true;
+    }
+
+    public void setMapValue( String name, String value ) {
+        this.mapValue.put( name, value );
+    }
+
+    public String getMapValue( String name ) {
+        return this.mapValue.get( name );
+    }
+
+    public String getProperty() {
+        return property;
+    }
+
+    public void setProperty(String pProperty) {
+        property = pProperty;
+    }
+
+}

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

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

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