You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2009/12/24 01:40:20 UTC
svn commit: r893662 - in /ofbiz/trunk/framework:
minilang/src/org/ofbiz/minilang/SimpleMethod.java
testtools/dtd/test-suite.xsd
testtools/src/org/ofbiz/testtools/ModelTestSuite.java
testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
Author: lektran
Date: Thu Dec 24 00:40:19 2009
New Revision: 893662
URL: http://svn.apache.org/viewvc?rev=893662&view=rev
Log:
Added the ability to include all tests from a given simple method document in a test suite by only specifying the location and not the method name. All simple methods with a method name beginning with "test" will be included and will be executed in the order present in the document. Example usage:
<test-case case-name="auto-accounting-transaction-tests">
<simple-method-test location="component://accounting/script/org/ofbiz/accounting/test/AutoAcctgTransTests.xml"/>
</test-case>
Basically just mimics the behavior of the junit-test-suite tag but for simple method tests
Modified:
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
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/SimpleMethodTest.java
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=893662&r1=893661&r2=893662&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Thu Dec 24 00:40:19 2009
@@ -197,6 +197,43 @@
return simpleMethods;
}
+ public static List<SimpleMethod> getSimpleMethodsList(String xmlResource, ClassLoader loader) throws MiniLangException {
+ List<SimpleMethod> simpleMethods = FastList.newInstance();
+
+ // Let the standard Map returning method take care of caching and compilation
+ Map<String, SimpleMethod> simpleMethodMap = SimpleMethod.getSimpleMethods(xmlResource, loader);
+
+ // Load and traverse the document again to get a correctly ordered list of methods
+ URL xmlURL = null;
+ try {
+ xmlURL = FlexibleLocation.resolveLocation(xmlResource, loader);
+ } catch (MalformedURLException e) {
+ throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource + "; error was: " + e.toString(), e);
+ }
+ // read in the file
+ Document document = null;
+ try {
+ document = UtilXml.readXmlDocument(xmlURL, true, true);
+ } catch (java.io.IOException e) {
+ throw new MiniLangException("Could not read XML file", e);
+ } catch (org.xml.sax.SAXException e) {
+ throw new MiniLangException("Could not parse XML file", e);
+ } catch (javax.xml.parsers.ParserConfigurationException e) {
+ throw new MiniLangException("XML parser not setup correctly", e);
+ }
+
+ if (document == null) {
+ throw new MiniLangException("Could not find SimpleMethod XML document: " + xmlURL.toString());
+ }
+
+ Element rootElement = document.getDocumentElement();
+ for (Element simpleMethodElement: UtilXml.childElementList(rootElement, "simple-method")) {
+ simpleMethods.add(simpleMethodMap.get(simpleMethodElement.getAttribute("method-name")));
+ }
+
+ return simpleMethods;
+ }
+
public static Map<String, SimpleMethod> getSimpleMethods(URL xmlURL) throws MiniLangException {
Map<String, SimpleMethod> simpleMethods = simpleMethodsURLCache.get(xmlURL);
Modified: ofbiz/trunk/framework/testtools/dtd/test-suite.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/dtd/test-suite.xsd?rev=893662&r1=893661&r2=893662&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/dtd/test-suite.xsd (original)
+++ ofbiz/trunk/framework/testtools/dtd/test-suite.xsd Thu Dec 24 00:40:19 2009
@@ -102,7 +102,14 @@
</xs:element>
<xs:attributeGroup name="attlist.simple-method-test">
<xs:attribute type="xs:string" name="location" use="required"/>
- <xs:attribute type="xs:string" name="name" use="required"/>
+ <xs:attribute type="xs:string" name="name">
+ <xs:annotation>
+ <xs:documentation>
+ The method-name of the simple-method to execute. If no name is supplied then all simple-methods from
+ location with a method-name beginning with "test" will be added as individual tests.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:attributeGroup>
<xs:element name="entity-xml" substitutionGroup="TestCaseTypes">
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=893662&r1=893661&r2=893662&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Thu Dec 24 00:40:19 2009
@@ -35,6 +35,8 @@
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.DelegatorFactory;
import org.ofbiz.entity.testtools.EntityTestCase;
+import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.SimpleMethod;
import org.ofbiz.service.GenericDispatcher;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.testtools.OFBizTestCase;
@@ -113,7 +115,23 @@
} else if ("service-test".equals(nodeName)) {
this.testList.add(new ServiceTest(caseName, testElement));
} else if ("simple-method-test".equals(nodeName)) {
- this.testList.add(new SimpleMethodTest(caseName, testElement));
+ if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) {
+ this.testList.add(new SimpleMethodTest(caseName, testElement));
+ } else {
+ String methodLocation = testElement.getAttribute("location");
+ List<SimpleMethod> simpleMethods;
+ try {
+ simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null);
+ for (SimpleMethod simpleMethod : simpleMethods) {
+ String methodName = simpleMethod.getMethodName();
+ if (methodName.startsWith("test")) {
+ this.testList.add(new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName));
+ }
+ }
+ } catch (MiniLangException e) {
+ Debug.logError(e, module);
+ }
+ }
} else if ("entity-xml".equals(nodeName)) {
this.testList.add(new EntityXmlAssertTest(caseName, testElement));
} else if ("entity-xml-assert".equals(nodeName)) {
Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java?rev=893662&r1=893661&r2=893662&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java Thu Dec 24 00:40:19 2009
@@ -45,9 +45,13 @@
* @param modelTestSuite
*/
public SimpleMethodTest(String caseName, Element mainElement) {
+ this(caseName, mainElement.getAttribute("location"), mainElement.getAttribute("name"));
+ }
+
+ public SimpleMethodTest(String caseName, String methodLocation, String methodName) {
super(caseName);
- this.methodLocation = mainElement.getAttribute("location");
- this.methodName = mainElement.getAttribute("name");
+ this.methodLocation = methodLocation;
+ this.methodName = methodName;
}
@Override
Re: svn commit: r893662 - in /ofbiz/trunk/framework:
minilang/src/org/ofbiz/minilang/SimpleMethod.java testtools/dtd/test-suite.xsd
testtools/src/org/ofbiz/testtools/ModelTestSuite.java testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
Posted by Ashish Vijaywargiya <vi...@gmail.com>.
Nice addition.
Thanks Scott !
--
Ashish
On Thu, Dec 24, 2009 at 6:10 AM, <le...@apache.org> wrote:
> Author: lektran
> Date: Thu Dec 24 00:40:19 2009
> New Revision: 893662
>
> URL: http://svn.apache.org/viewvc?rev=893662&view=rev
> Log:
> Added the ability to include all tests from a given simple method document in a test suite by only specifying the location and not the method name. All simple methods with a method name beginning with "test" will be included and will be executed in the order present in the document. Example usage:
> <test-case case-name="auto-accounting-transaction-tests">
> <simple-method-test location="component://accounting/script/org/ofbiz/accounting/test/AutoAcctgTransTests.xml"/>
> </test-case>
> Basically just mimics the behavior of the junit-test-suite tag but for simple method tests
>
> Modified:
> ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
> 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/SimpleMethodTest.java
>
> Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=893662&r1=893661&r2=893662&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
> +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Thu Dec 24 00:40:19 2009
> @@ -197,6 +197,43 @@
> return simpleMethods;
> }
>
> + public static List<SimpleMethod> getSimpleMethodsList(String xmlResource, ClassLoader loader) throws MiniLangException {
> + List<SimpleMethod> simpleMethods = FastList.newInstance();
> +
> + // Let the standard Map returning method take care of caching and compilation
> + Map<String, SimpleMethod> simpleMethodMap = SimpleMethod.getSimpleMethods(xmlResource, loader);
> +
> + // Load and traverse the document again to get a correctly ordered list of methods
> + URL xmlURL = null;
> + try {
> + xmlURL = FlexibleLocation.resolveLocation(xmlResource, loader);
> + } catch (MalformedURLException e) {
> + throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource + "; error was: " + e.toString(), e);
> + }
> + // read in the file
> + Document document = null;
> + try {
> + document = UtilXml.readXmlDocument(xmlURL, true, true);
> + } catch (java.io.IOException e) {
> + throw new MiniLangException("Could not read XML file", e);
> + } catch (org.xml.sax.SAXException e) {
> + throw new MiniLangException("Could not parse XML file", e);
> + } catch (javax.xml.parsers.ParserConfigurationException e) {
> + throw new MiniLangException("XML parser not setup correctly", e);
> + }
> +
> + if (document == null) {
> + throw new MiniLangException("Could not find SimpleMethod XML document: " + xmlURL.toString());
> + }
> +
> + Element rootElement = document.getDocumentElement();
> + for (Element simpleMethodElement: UtilXml.childElementList(rootElement, "simple-method")) {
> + simpleMethods.add(simpleMethodMap.get(simpleMethodElement.getAttribute("method-name")));
> + }
> +
> + return simpleMethods;
> + }
> +
> public static Map<String, SimpleMethod> getSimpleMethods(URL xmlURL) throws MiniLangException {
> Map<String, SimpleMethod> simpleMethods = simpleMethodsURLCache.get(xmlURL);
>
>
> Modified: ofbiz/trunk/framework/testtools/dtd/test-suite.xsd
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/dtd/test-suite.xsd?rev=893662&r1=893661&r2=893662&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/testtools/dtd/test-suite.xsd (original)
> +++ ofbiz/trunk/framework/testtools/dtd/test-suite.xsd Thu Dec 24 00:40:19 2009
> @@ -102,7 +102,14 @@
> </xs:element>
> <xs:attributeGroup name="attlist.simple-method-test">
> <xs:attribute type="xs:string" name="location" use="required"/>
> - <xs:attribute type="xs:string" name="name" use="required"/>
> + <xs:attribute type="xs:string" name="name">
> + <xs:annotation>
> + <xs:documentation>
> + The method-name of the simple-method to execute. If no name is supplied then all simple-methods from
> + location with a method-name beginning with "test" will be added as individual tests.
> + </xs:documentation>
> + </xs:annotation>
> + </xs:attribute>
> </xs:attributeGroup>
>
> <xs:element name="entity-xml" substitutionGroup="TestCaseTypes">
>
> 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=893662&r1=893661&r2=893662&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original)
> +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Thu Dec 24 00:40:19 2009
> @@ -35,6 +35,8 @@
> import org.ofbiz.entity.Delegator;
> import org.ofbiz.entity.DelegatorFactory;
> import org.ofbiz.entity.testtools.EntityTestCase;
> +import org.ofbiz.minilang.MiniLangException;
> +import org.ofbiz.minilang.SimpleMethod;
> import org.ofbiz.service.GenericDispatcher;
> import org.ofbiz.service.LocalDispatcher;
> import org.ofbiz.service.testtools.OFBizTestCase;
> @@ -113,7 +115,23 @@
> } else if ("service-test".equals(nodeName)) {
> this.testList.add(new ServiceTest(caseName, testElement));
> } else if ("simple-method-test".equals(nodeName)) {
> - this.testList.add(new SimpleMethodTest(caseName, testElement));
> + if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) {
> + this.testList.add(new SimpleMethodTest(caseName, testElement));
> + } else {
> + String methodLocation = testElement.getAttribute("location");
> + List<SimpleMethod> simpleMethods;
> + try {
> + simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null);
> + for (SimpleMethod simpleMethod : simpleMethods) {
> + String methodName = simpleMethod.getMethodName();
> + if (methodName.startsWith("test")) {
> + this.testList.add(new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName));
> + }
> + }
> + } catch (MiniLangException e) {
> + Debug.logError(e, module);
> + }
> + }
> } else if ("entity-xml".equals(nodeName)) {
> this.testList.add(new EntityXmlAssertTest(caseName, testElement));
> } else if ("entity-xml-assert".equals(nodeName)) {
>
> Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java?rev=893662&r1=893661&r2=893662&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java (original)
> +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java Thu Dec 24 00:40:19 2009
> @@ -45,9 +45,13 @@
> * @param modelTestSuite
> */
> public SimpleMethodTest(String caseName, Element mainElement) {
> + this(caseName, mainElement.getAttribute("location"), mainElement.getAttribute("name"));
> + }
> +
> + public SimpleMethodTest(String caseName, String methodLocation, String methodName) {
> super(caseName);
> - this.methodLocation = mainElement.getAttribute("location");
> - this.methodName = mainElement.getAttribute("name");
> + this.methodLocation = methodLocation;
> + this.methodName = methodName;
> }
>
> @Override
>
>
>