Author: doogie
Date: Thu Mar 5 02:40:06 2009 New Revision: 750296 URL: http://svn.apache.org/viewvc?rev=750296&view=rev Log: Add a <test-group> element, that is a sibling of <test-case>; this element can take a list of child test definitions. Modified: ofbiz/trunk/framework/testtools/dtd/test-suite.xsd ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java Modified: ofbiz/trunk/framework/testtools/dtd/test-suite.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/dtd/test-suite.xsd?rev=750296&r1=750295&r2=750296&view=diff ============================================================================== --- ofbiz/trunk/framework/testtools/dtd/test-suite.xsd (original) +++ ofbiz/trunk/framework/testtools/dtd/test-suite.xsd Thu Mar 5 02:40:06 2009 @@ -36,9 +36,10 @@ <!-- ELEMENTS start here --> <xs:element name="test-suite"> <xs:complexType> - <xs:sequence> - <xs:element minOccurs="1" maxOccurs="unbounded" ref="test-case"/> - </xs:sequence> + <xs:choice minOccurs="1" maxOccurs="unbounded"> + <xs:element ref="test-case"/> + <xs:element ref="test-group"/> + </xs:choice> <xs:attributeGroup ref="attlist.test-suite"/> </xs:complexType> </xs:element> @@ -57,6 +58,16 @@ <xs:attributeGroup name="attlist.test-case"> <xs:attribute type="xs:string" name="case-name" use="required"/> </xs:attributeGroup> + <xs:element name="test-group"> + <xs:annotation><xs:documentation></xs:documentation></xs:annotation> + <xs:complexType> + <xs:group minOccurs="1" maxOccurs="unbounded" ref="AllTestCaseTypes"/> + <xs:attributeGroup ref="attlist.test-group"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="attlist.test-group"> + <xs:attribute type="xs:string" name="case-name" use="required"/> + </xs:attributeGroup> <xs:element name="junit-test-suite" substitutionGroup="TestCaseTypes"> <xs:annotation><xs:documentation>Used for JUnit test suites written as a Java class.</xs:documentation></xs:annotation> Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java?rev=750296&r1=750295&r2=750296&view=diff ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Thu Mar 5 02:40:06 2009 @@ -28,6 +28,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.GenericDelegator; @@ -63,47 +64,60 @@ this.delegator = GenericDelegator.getGenericDelegator(this.delegatorName); this.dispatcher = GenericDispatcher.getLocalDispatcher(this.dispatcherName, delegator); - for (Element testCaseElement : UtilXml.childElementList(mainElement, "test-case")) { + for (Element testCaseElement : UtilXml.childElementList(mainElement, UtilMisc.toSet("test-case", "test-group"))) { String caseName = testCaseElement.getAttribute("case-name"); + String nodeName = testCaseElement.getNodeName(); if (testCase == null || caseName.equals(testCase)) { - Element childElement = UtilXml.firstChildElement(testCaseElement); - String nodeName = childElement.getNodeName(); - if ("junit-test-suite".equals(nodeName)) { - String className = childElement.getAttribute("class-name"); - - try { - Class clz = ObjectType.loadClass(className); - TestSuite suite = new TestSuite(); - suite.addTestSuite(clz); - Enumeration testEnum = suite.tests(); - int testsAdded = 0; - int casesAdded = 0; - while (testEnum.hasMoreElements()) { - Test tst = (Test) testEnum.nextElement(); - this.testList.add(tst); - casesAdded += tst.countTestCases(); - testsAdded++; - } - Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); - } catch (Exception e) { - String errMsg = "Unable to load test suite class : " + className; - Debug.logError(e, errMsg, module); + if (nodeName.equals("test-case")) { + parseTestElement(caseName, UtilXml.firstChildElement(testCaseElement)); + } else if (nodeName.equals("test-group")) { + int i = 0; + for (Element childElement: UtilXml.childElementList(testCaseElement)) { + parseTestElement(caseName + '-' + i, childElement); + i++; } - } else if ("service-test".equals(nodeName)) { - this.testList.add(new ServiceTest(caseName, this, childElement)); - } else if ("simple-method-test".equals(nodeName)) { - this.testList.add(new SimpleMethodTest(caseName, this, childElement)); - } else if ("entity-xml".equals(nodeName)) { - this.testList.add(new EntityXmlAssertTest(caseName, this, childElement)); - } else if ("entity-xml-assert".equals(nodeName)) { - // this is the old, deprecated name for the element, changed because it now does assert or load - this.testList.add(new EntityXmlAssertTest(caseName, this, childElement)); - } else if ("jython-test".equals(nodeName)) { - this.testList.add(new JythonTest(caseName, this, childElement)); } } } } + + private void parseTestElement(String caseName, Element testElement) { + String nodeName = testElement.getNodeName(); + if ("junit-test-suite".equals(nodeName)) { + String className = testElement.getAttribute("class-name"); + + try { + Class clz = ObjectType.loadClass(className); + TestSuite suite = new TestSuite(); + suite.addTestSuite(clz); + Enumeration testEnum = suite.tests(); + int testsAdded = 0; + int casesAdded = 0; + while (testEnum.hasMoreElements()) { + Test tst = (Test) testEnum.nextElement(); + this.testList.add(tst); + casesAdded += tst.countTestCases(); + testsAdded++; + } + Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); + } catch (Exception e) { + String errMsg = "Unable to load test suite class : " + className; + Debug.logError(e, errMsg, module); + } + } else if ("service-test".equals(nodeName)) { + this.testList.add(new ServiceTest(caseName, this, testElement)); + } else if ("simple-method-test".equals(nodeName)) { + this.testList.add(new SimpleMethodTest(caseName, this, testElement)); + } else if ("entity-xml".equals(nodeName)) { + this.testList.add(new EntityXmlAssertTest(caseName, this, testElement)); + } else if ("entity-xml-assert".equals(nodeName)) { + // this is the old, deprecated name for the element, changed because it now does assert or load + this.testList.add(new EntityXmlAssertTest(caseName, this, testElement)); + } else if ("jython-test".equals(nodeName)) { + this.testList.add(new JythonTest(caseName, this, testElement)); + } + + } String getSuiteName() { return this.suiteName; Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java?rev=750296&r1=750295&r2=750296&view=diff ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java Thu Mar 5 02:40:06 2009 @@ -27,6 +27,7 @@ import org.ofbiz.base.container.Container; import org.ofbiz.base.container.ContainerException; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilXml; import java.io.File; @@ -69,7 +70,7 @@ try { Document testSuiteDocument = testSuiteResource.getDocument(); Element documentElement = testSuiteDocument.getDocumentElement(); - for (Element testCaseElement : UtilXml.childElementList(documentElement, "test-case")) { + for (Element testCaseElement : UtilXml.childElementList(documentElement, UtilMisc.toSet("test-case", "test-group"))) { String caseName = testCaseElement.getAttribute("case-name"); pout.println(componentName + ":" + caseName); } |
Why not just use different test-suite elements for this? Why have an hierarchy in this? Actually... I'm not even sure what "this" is, ie what is the point of a group? Maybe we should discuss that first... -David On Mar 4, 2009, at 7:40 PM, [hidden email] wrote: > Author: doogie > Date: Thu Mar 5 02:40:06 2009 > New Revision: 750296 > > URL: http://svn.apache.org/viewvc?rev=750296&view=rev > Log: > Add a <test-group> element, that is a sibling of <test-case>; this > element can take a list of child test definitions. > > Modified: > ofbiz/trunk/framework/testtools/dtd/test-suite.xsd > ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > ModelTestSuite.java > ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > TestListContainer.java > > Modified: ofbiz/trunk/framework/testtools/dtd/test-suite.xsd > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/dtd/test-suite.xsd?rev=750296&r1=750295&r2=750296&view=diff > = > = > = > = > = > = > = > = > ====================================================================== > --- ofbiz/trunk/framework/testtools/dtd/test-suite.xsd (original) > +++ ofbiz/trunk/framework/testtools/dtd/test-suite.xsd Thu Mar 5 > 02:40:06 2009 > @@ -36,9 +36,10 @@ > <!-- ELEMENTS start here --> > <xs:element name="test-suite"> > <xs:complexType> > - <xs:sequence> > - <xs:element minOccurs="1" maxOccurs="unbounded" > ref="test-case"/> > - </xs:sequence> > + <xs:choice minOccurs="1" maxOccurs="unbounded"> > + <xs:element ref="test-case"/> > + <xs:element ref="test-group"/> > + </xs:choice> > <xs:attributeGroup ref="attlist.test-suite"/> > </xs:complexType> > </xs:element> > @@ -57,6 +58,16 @@ > <xs:attributeGroup name="attlist.test-case"> > <xs:attribute type="xs:string" name="case-name" > use="required"/> > </xs:attributeGroup> > + <xs:element name="test-group"> > + <xs:annotation><xs:documentation></xs:documentation></ > xs:annotation> > + <xs:complexType> > + <xs:group minOccurs="1" maxOccurs="unbounded" > ref="AllTestCaseTypes"/> > + <xs:attributeGroup ref="attlist.test-group"/> > + </xs:complexType> > + </xs:element> > + <xs:attributeGroup name="attlist.test-group"> > + <xs:attribute type="xs:string" name="case-name" > use="required"/> > + </xs:attributeGroup> > > <xs:element name="junit-test-suite" > substitutionGroup="TestCaseTypes"> > <xs:annotation><xs:documentation>Used for JUnit test suites > written as a Java class.</xs:documentation></xs:annotation> > > Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > ModelTestSuite.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java?rev=750296&r1=750295&r2=750296&view=diff > = > = > = > = > = > = > = > = > ====================================================================== > --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > ModelTestSuite.java (original) > +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > ModelTestSuite.java Thu Mar 5 02:40:06 2009 > @@ -28,6 +28,7 @@ > > import org.ofbiz.base.util.Debug; > import org.ofbiz.base.util.ObjectType; > +import org.ofbiz.base.util.UtilMisc; > import org.ofbiz.base.util.UtilValidate; > import org.ofbiz.base.util.UtilXml; > import org.ofbiz.entity.GenericDelegator; > @@ -63,47 +64,60 @@ > this.delegator = > GenericDelegator.getGenericDelegator(this.delegatorName); > this.dispatcher = > GenericDispatcher.getLocalDispatcher(this.dispatcherName, delegator); > > - for (Element testCaseElement : > UtilXml.childElementList(mainElement, "test-case")) { > + for (Element testCaseElement : > UtilXml.childElementList(mainElement, UtilMisc.toSet("test-case", > "test-group"))) { > String caseName = testCaseElement.getAttribute("case- > name"); > + String nodeName = testCaseElement.getNodeName(); > if (testCase == null || caseName.equals(testCase)) { > - Element childElement = > UtilXml.firstChildElement(testCaseElement); > - String nodeName = childElement.getNodeName(); > - if ("junit-test-suite".equals(nodeName)) { > - String className = > childElement.getAttribute("class-name"); > - > - try { > - Class clz = ObjectType.loadClass(className); > - TestSuite suite = new TestSuite(); > - suite.addTestSuite(clz); > - Enumeration testEnum = suite.tests(); > - int testsAdded = 0; > - int casesAdded = 0; > - while (testEnum.hasMoreElements()) { > - Test tst = (Test) testEnum.nextElement(); > - this.testList.add(tst); > - casesAdded += tst.countTestCases(); > - testsAdded++; > - } > - Debug.logInfo("Added " + testsAdded + " > tests [" + casesAdded + " cases] from the class: " + className, > module); > - } catch (Exception e) { > - String errMsg = "Unable to load test suite > class : " + className; > - Debug.logError(e, errMsg, module); > + if (nodeName.equals("test-case")) { > + parseTestElement(caseName, > UtilXml.firstChildElement(testCaseElement)); > + } else if (nodeName.equals("test-group")) { > + int i = 0; > + for (Element childElement: > UtilXml.childElementList(testCaseElement)) { > + parseTestElement(caseName + '-' + i, > childElement); > + i++; > } > - } else if ("service-test".equals(nodeName)) { > - this.testList.add(new ServiceTest(caseName, > this, childElement)); > - } else if ("simple-method-test".equals(nodeName)) { > - this.testList.add(new > SimpleMethodTest(caseName, this, childElement)); > - } else if ("entity-xml".equals(nodeName)) { > - this.testList.add(new > EntityXmlAssertTest(caseName, this, childElement)); > - } else if ("entity-xml-assert".equals(nodeName)) { > - // this is the old, deprecated name for the > element, changed because it now does assert or load > - this.testList.add(new > EntityXmlAssertTest(caseName, this, childElement)); > - } else if ("jython-test".equals(nodeName)) { > - this.testList.add(new JythonTest(caseName, > this, childElement)); > } > } > } > } > + > + private void parseTestElement(String caseName, Element > testElement) { > + String nodeName = testElement.getNodeName(); > + if ("junit-test-suite".equals(nodeName)) { > + String className = testElement.getAttribute("class- > name"); > + > + try { > + Class clz = ObjectType.loadClass(className); > + TestSuite suite = new TestSuite(); > + suite.addTestSuite(clz); > + Enumeration testEnum = suite.tests(); > + int testsAdded = 0; > + int casesAdded = 0; > + while (testEnum.hasMoreElements()) { > + Test tst = (Test) testEnum.nextElement(); > + this.testList.add(tst); > + casesAdded += tst.countTestCases(); > + testsAdded++; > + } > + Debug.logInfo("Added " + testsAdded + " tests [" + > casesAdded + " cases] from the class: " + className, module); > + } catch (Exception e) { > + String errMsg = "Unable to load test suite class : > " + className; > + Debug.logError(e, errMsg, module); > + } > + } else if ("service-test".equals(nodeName)) { > + this.testList.add(new ServiceTest(caseName, this, > testElement)); > + } else if ("simple-method-test".equals(nodeName)) { > + this.testList.add(new SimpleMethodTest(caseName, this, > testElement)); > + } else if ("entity-xml".equals(nodeName)) { > + this.testList.add(new EntityXmlAssertTest(caseName, > this, testElement)); > + } else if ("entity-xml-assert".equals(nodeName)) { > + // this is the old, deprecated name for the element, > changed because it now does assert or load > + this.testList.add(new EntityXmlAssertTest(caseName, > this, testElement)); > + } else if ("jython-test".equals(nodeName)) { > + this.testList.add(new JythonTest(caseName, this, > testElement)); > + } > + > + } > > String getSuiteName() { > return this.suiteName; > > Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > TestListContainer.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java?rev=750296&r1=750295&r2=750296&view=diff > = > = > = > = > = > = > = > = > ====================================================================== > --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > TestListContainer.java (original) > +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ > TestListContainer.java Thu Mar 5 02:40:06 2009 > @@ -27,6 +27,7 @@ > import org.ofbiz.base.container.Container; > import org.ofbiz.base.container.ContainerException; > import org.ofbiz.base.util.Debug; > +import org.ofbiz.base.util.UtilMisc; > import org.ofbiz.base.util.UtilXml; > > import java.io.File; > @@ -69,7 +70,7 @@ > try { > Document testSuiteDocument = > testSuiteResource.getDocument(); > Element documentElement = > testSuiteDocument.getDocumentElement(); > - for (Element testCaseElement : > UtilXml.childElementList(documentElement, "test-case")) { > + for (Element testCaseElement : > UtilXml.childElementList(documentElement, UtilMisc.toSet("test- > case", "test-group"))) { > String caseName = > testCaseElement.getAttribute("case-name"); > pout.println(componentName + ":" + caseName); > } > > |
Free forum by Nabble | Edit this page |