vhardy 2003/07/07 02:35:50 Modified: test-sources/org/apache/batik/test/xml XMLReflect.java Added: test-sources/org/apache/batik/test ParametrizedTest.java Log: Added inheritance for <property> on test instances. Now, testGroups can define default property values for children tests Revision Changes Path 1.1 xml-batik/test-sources/org/apache/batik/test/ParametrizedTest.java Index: ParametrizedTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.test; import java.util.Vector; /** * This test validates that test properties are inherited from the class that * defines the "class" attribute down to each test instance that uses the * same class. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> * @version $Id: ParametrizedTest.java,v 1.1 2003/07/07 09:35:49 vhardy Exp $ */ public class ParametrizedTest extends AbstractTest { protected String A = "initial_A_value"; protected String B = "initial_B_value"; protected String expectedA = "unset"; protected String expectedB = "unset"; public void setA(String A) { this.A = A; } public void setB(String B) { this.B = B; } public void setExpectedA(String expectedA) { this.expectedA = expectedA; } public void setExpectedB(String expectedB) { this.expectedB = expectedB; } public String getA() { return A; } public String getB() { return B; } public String getExpectedA() { return expectedA; } public String getExpectedB() { return expectedB; } public TestReport runImpl() throws Exception { if (!A.equals(expectedA) || !B.equals(expectedB)) { TestReport r = reportError("Unexpected A or B value"); r.addDescriptionEntry("expected.A", expectedA); r.addDescriptionEntry("actual.A", A); r.addDescriptionEntry("expected.B", expectedB); r.addDescriptionEntry("actual.B", B); return r; } return reportSuccess(); } } 1.8 +47 -26 xml-batik/test-sources/org/apache/batik/test/xml/XMLReflect.java Index: XMLReflect.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XMLReflect.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XMLReflect.java 4 Jul 2003 15:57:36 -0000 1.7 +++ XMLReflect.java 7 Jul 2003 09:35:50 -0000 1.8 @@ -40,8 +40,11 @@ */ public static Object buildObject(Element element) throws Exception { + Element classDefiningElement = + getClassDefiningElement(element); + String className - = getInheritedClassAttribute(element); + = classDefiningElement.getAttribute(XR_CLASS_ATTRIBUTE); Class cl = Class.forName(className); Object[] argsArray = null; @@ -91,32 +94,48 @@ argsClassesStr })); } return configureObject(constructor.newInstance(argsArray), - element); + element, classDefiningElement); } /** * Implementation helper: configures a generic object */ public static Object configureObject(Object obj, - Element element) throws Exception { - NodeList children = element.getChildNodes(); - if(children != null && children.getLength() > 0){ - int n = children.getLength(); - Vector args = new Vector(); - for(int i=0; i<n; i++){ - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE){ - Element childElement = (Element)child; - String tagName = childElement.getTagName().intern(); - if(tagName == XR_PROPERTY_TAG){ - Object arg = buildArgument(childElement); - String propertyName - = childElement.getAttribute(XR_NAME_ATTRIBUTE); - setObjectProperty(obj, propertyName, arg); + Element element, + Element classDefiningElement) throws Exception { + // First, build a vector of elements from the child element + // to the classDefiningElement so that we can go from the + // top (classDefiningElement) to the child and apply properties + // as we iterate + Vector v = new Vector(); + v.addElement(element); + while (element != classDefiningElement) { + element = (Element) element.getParentNode(); + v.addElement(element); + } + + int ne = v.size(); + for (int j=ne-1; j>=0; j--) { + element = (Element)v.elementAt(j); + NodeList children = element.getChildNodes(); + if(children != null && children.getLength() > 0){ + int n = children.getLength(); + Vector args = new Vector(); + for(int i=0; i<n; i++){ + Node child = children.item(i); + if(child.getNodeType() == Node.ELEMENT_NODE){ + Element childElement = (Element)child; + String tagName = childElement.getTagName().intern(); + if(tagName == XR_PROPERTY_TAG){ + Object arg = buildArgument(childElement); + String propertyName + = childElement.getAttribute(XR_NAME_ATTRIBUTE); + setObjectProperty(obj, propertyName, arg); + } } } + } - } return obj; @@ -129,6 +148,7 @@ String propertyName, Object propertyValue) throws Exception { + System.err.println(">>>>>>>>>>> setObjectProperty (" + obj.getClass().getName() + ", " + propertyName + ", " + propertyValue + ")"); Class cl = obj.getClass(); Method m = null; try { @@ -208,7 +228,10 @@ */ public static Object buildArgument(Element element) throws Exception { if(!element.hasChildNodes()){ - String classAttr = getInheritedClassAttribute(element); + Element classDefiningElement = + getClassDefiningElement(element); + + String classAttr = classDefiningElement.getAttribute(XR_CLASS_ATTRIBUTE); // String based argument Class cl = Class.forName(classAttr); @@ -233,25 +256,23 @@ } /** - * The class name to use is that of the element itself or, if not - * specified, that of its closest ancestor which defines it - * (through the XR_CLASS_ATTRIBUTE + * Gets the defining class element */ - public static String getInheritedClassAttribute(Element element){ + public static Element getClassDefiningElement(Element element) { if(element != null){ String classAttr = element.getAttribute(XR_CLASS_ATTRIBUTE); if(classAttr == null || "".equals(classAttr)){ Node parent = element.getParentNode(); if(parent != null && parent.getNodeType() == Node.ELEMENT_NODE){ - return getInheritedClassAttribute((Element)parent); + return getClassDefiningElement((Element)parent); } else{ return null; } } - return classAttr; + return element; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]