You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by pg...@apache.org on 2021/09/15 13:37:52 UTC
[ofbiz-framework] branch trunk updated: Implemented: Reintroduce
groovy-test-suite test case (OFBIZ-12320)
This is an automated email from the ASF dual-hosted git repository.
pgil pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new f790b7a Implemented: Reintroduce groovy-test-suite test case (OFBIZ-12320)
f790b7a is described below
commit f790b7a6ef97bfe04674ae0eab10840275a1c70e
Author: Gil Portenseigne <pg...@apache.org>
AuthorDate: Wed Sep 15 14:47:23 2021 +0200
Implemented: Reintroduce groovy-test-suite test case (OFBIZ-12320)
This test case engine allow writing test in groovy script that do not
need compilation.
---
.../base/groovyScripts/test/SimpleTests.groovy | 41 ++++++++++++++++
framework/base/testdef/basetests.xml | 2 +-
framework/testtools/dtd/test-suite.xsd | 22 +++++++++
.../ofbiz/testtools/GroovyScriptTestCase.java | 54 ++++++++++++++++++++++
.../org/apache/ofbiz/testtools/ModelTestSuite.java | 18 ++++++++
5 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/framework/base/groovyScripts/test/SimpleTests.groovy b/framework/base/groovyScripts/test/SimpleTests.groovy
new file mode 100644
index 0000000..16800c1
--- /dev/null
+++ b/framework/base/groovyScripts/test/SimpleTests.groovy
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.
+ *******************************************************************************/
+import org.apache.ofbiz.testtools.GroovyScriptTestCase
+
+class BaseTest extends GroovyScriptTestCase {
+ void testTrue() {
+ assert 1, 1
+ }
+
+ void testFalse() {
+ assertNotSame 1, 0
+ }
+
+ void testDelegator() {
+ assert delegator
+ }
+
+ void testDispatcher() {
+ assert dispatcher
+ }
+
+ void testSecurity() {
+ assert security
+ }
+}
diff --git a/framework/base/testdef/basetests.xml b/framework/base/testdef/basetests.xml
index 718b0d4..4736c63 100644
--- a/framework/base/testdef/basetests.xml
+++ b/framework/base/testdef/basetests.xml
@@ -25,6 +25,6 @@
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilObjectTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.string.test.FlexibleStringExpanderTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.collections.test.FlexibleMapAccessorTests"/>
- <junit-test-suite class-name="org.apache.ofbiz.base.SimpleTests"/>
+ <groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/>
</test-group>
</test-suite>
diff --git a/framework/testtools/dtd/test-suite.xsd b/framework/testtools/dtd/test-suite.xsd
index 04ffbf1..e9ee0e2 100644
--- a/framework/testtools/dtd/test-suite.xsd
+++ b/framework/testtools/dtd/test-suite.xsd
@@ -84,6 +84,28 @@ under the License.
</xs:attribute>
</xs:attributeGroup>
+ <xs:element name="groovy-test-suite" substitutionGroup="TestCaseTypes">
+ <xs:annotation>
+ <xs:documentation>
+ Used for JUnit test suites written as a Groovy class. See http://groovy-lang.org/testing.html
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attributeGroup ref="attlist.groovy-test-suite"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:attributeGroup name="attlist.groovy-test-suite">
+ <xs:attribute type="xs:string" name="name"/>
+ <xs:attribute type="xs:string" name="location" use="required">
+ <xs:annotation>
+ <xs:documentation>
+ Give the location where is groovy file that contaions the test suite.
+ You can use a flexible url location like component://mycomponent/groovyScripts/test/MySuiteTest.groovy
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:attributeGroup>
+
<xs:element name="service-test" substitutionGroup="TestCaseTypes">
<xs:complexType>
<xs:attributeGroup ref="attlist.service-test"/>
diff --git a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/GroovyScriptTestCase.java b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/GroovyScriptTestCase.java
new file mode 100644
index 0000000..5b8b689
--- /dev/null
+++ b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/GroovyScriptTestCase.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.ofbiz.testtools;
+
+import groovy.util.GroovyTestCase;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.security.Security;
+import org.apache.ofbiz.service.LocalDispatcher;
+
+/**
+ * This test case engine allow writing test in groovy script that do not need compilation.
+ */
+public class GroovyScriptTestCase extends GroovyTestCase {
+
+ private Delegator delegator;
+ private LocalDispatcher dispatcher;
+ private Security security;
+
+ public final void setDelegator(Delegator delegator) {
+ this.delegator = delegator;
+ }
+ public final Delegator getDelegator() {
+ return delegator;
+ }
+
+ public final LocalDispatcher getDispatcher() {
+ return dispatcher;
+ }
+ public final void setDispatcher(LocalDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+ public final void setSecurity(Security security) {
+ this.security = security;
+ }
+ public final Security getSecurity() {
+ return security;
+ }
+}
diff --git a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
index 9477322..f5639a5 100644
--- a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
+++ b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
@@ -25,6 +25,8 @@ import java.util.List;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.GeneralException;
+import org.apache.ofbiz.base.util.GroovyUtil;
import org.apache.ofbiz.base.util.ObjectType;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
@@ -104,6 +106,14 @@ public class ModelTestSuite {
String errMsg = "Unable to load test suite class : " + className;
Debug.logError(e, errMsg, MODULE);
}
+ } else if ("groovy-test-suite".equals(nodeName)) {
+ try {
+ Class<? extends TestCase> testClass =
+ UtilGenerics.cast(GroovyUtil.getScriptClassFromLocation(testElement.getAttribute("location")));
+ this.testList.add(new TestSuite(testClass, testElement.getAttribute("name")));
+ } catch (GeneralException e) {
+ Debug.logError(e, MODULE);
+ }
} else if ("service-test".equals(nodeName)) {
this.testList.add(new ServiceTest(caseName, testElement));
} else if ("simple-method-test".equals(nodeName)) {
@@ -193,6 +203,14 @@ public class ModelTestSuite {
if (test instanceof OFBizTestCase) {
((OFBizTestCase) test).setDispatcher(dispatcher);
}
+ } else if (test instanceof GroovyScriptTestCase) {
+ prepareGroovyScriptTestCase((GroovyScriptTestCase) test);
}
}
+
+ private void prepareGroovyScriptTestCase(GroovyScriptTestCase test) {
+ test.setDelegator(delegator);
+ test.setDispatcher(dispatcher);
+ test.setSecurity(dispatcher.getSecurity());
+ }
}