This is an automated email from the ASF dual-hosted git repository.
jleroux 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 88577c5072 Fixed: Fix groovy tests source setup (OFBIZ-13334)
88577c5072 is described below
commit 88577c5072e5010e08c8945b9f57fd3c6991fe28
Author: Jacques Le Roux <[email protected]>
AuthorDate: Fri Jan 9 11:51:20 2026 +0100
Fixed: Fix groovy tests source setup (OFBIZ-13334)
Following discussion in OFBIZ-13311 , some groovy tests should be moved or
turned into integration tests.
This would allow groovy tests source files to be removed from build.gradle
file.
Thanks: Gaetan for Jira creation and heads up
---
build.gradle | 11 ++-----
docs/asciidoc/developer-manual.adoc | 4 +--
framework/base/ofbiz-component.xml | 2 ++
.../org/apache/ofbiz/base/test/SimpleTests.groovy | 11 +++++--
framework/base/testdef/basetests.xml | 26 ++++++++++++++++
framework/service/servicedef/services_test_se.xml | 8 ++---
.../ofbiz/service/test/ServicePurgeTest.groovy | 11 +++++--
.../apache/ofbiz/service/test/TestServices.groovy} | 35 ++++++++++++----------
.../test/ServiceEngineTestPermissionServices.java | 4 +--
framework/service/testdef/servicetests.xml | 3 ++
10 files changed, 76 insertions(+), 39 deletions(-)
diff --git a/build.gradle b/build.gradle
index 9610468c58..2d5bbb6f5e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -278,7 +278,7 @@ def excludedJavaSources = [
]
sourceSets {
- // This is for integration tests (DB access)
+ // This is for integration tests (needs DB access or simply creation of
delegator or dispatcher that ultimately needs use of dispatcherFactory)
main {
java {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
@@ -293,23 +293,18 @@ sourceSets {
srcDirs += getDirectoryInActiveComponentsIfExists('dtd')
}
}
- // This is for unit tests (no DB access)
+ // This is for unit tests (no DB access need, or simply creation of
delegator or dispatcher that ultimately needs use of dispatcherFactory)
test {
java {
srcDirs = getDirectoryInActiveComponentsIfExists('src/test/java')
}
- // Groovy tests often fail, because JUNIT does not have access to the
ofbiz enviroment.
+ // Groovy tests often fail, because JUNIT does not have access to the
ofbiz environment.
// If a groovy test is supposed to be tested this way, it can be added
here.
groovy {
srcDirs = getDirectoryInActiveComponentsIfExists('src/test/groovy')
include 'org/apache/ofbiz/service/ModelServiceTest.groovy'
- include 'org/apache/ofbiz/test/TestServices.groovy'
include
'org/apache/ofbiz/base/util/string/FlexibleStringExpanderBaseCodeTests.groovy'
include 'org/apache/ofbiz/base/util/FileUtilTests.groovy'
- include 'org/apache/ofbiz/service/test/ServicePurgeTest.groovy'
- include 'org/apache/ofbiz/base/util/UtilCacheTest.groovy'
- include 'org/apache/ofbiz/base/util/tool/UtilCacheTestTools.groovy'
- include 'org.apache.ofbiz.base.test.SimpleTests.groovy'
}
resources {
srcDirs =
getDirectoryInActiveComponentsIfExists('src/test/resources')
diff --git a/docs/asciidoc/developer-manual.adoc
b/docs/asciidoc/developer-manual.adoc
index 2699db2b46..059ffca181 100644
--- a/docs/asciidoc/developer-manual.adoc
+++ b/docs/asciidoc/developer-manual.adoc
@@ -83,9 +83,9 @@ component-name-here/
├── servicedef - Defined services.
├── src/
├── docs/ - component documentation source
- └── main/groovy/ - A collection of scripts written in Groovy
+ └── main/groovy/ - A collection of scripts written in Groovy for
integration tests (needs DB access or simply creation of delegator or
dispatcher that ultimately needs use of dispatcherFactory)
└── main/java/ - java source code
- └── test/groovy/ - A collection of scripts written in Groovy
+ └── test/groovy/ - A collection of scripts written in Groovy for
unit-tests (no DB access need, or simply creation of delegator or dispatcher
that ultimately needs use of dispatcherFactory)
└── test/java/ - java unit-tests
├── testdef - Defined integration-tests
├── webapp - One or more Java webapps including the control
servlet
diff --git a/framework/base/ofbiz-component.xml
b/framework/base/ofbiz-component.xml
index bbbe28188e..8cde8e9ff9 100644
--- a/framework/base/ofbiz-component.xml
+++ b/framework/base/ofbiz-component.xml
@@ -24,6 +24,8 @@ under the License.
<resource-loader name="main" type="component"/>
<classpath type="dir" location="config"/>
+ <test-suite loader="main" location="testdef/basetests.xml"/>
+
<!-- load the naming (JNDI) server -->
<container name="naming-container" loaders="rmi"
class="org.apache.ofbiz.base.container.NamingServiceContainer">
<property name="host" value="0.0.0.0"/>
diff --git
a/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
b/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
index 8ca4ff0cd6..e24f032c4f 100644
---
a/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
+++
b/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
@@ -18,12 +18,17 @@
*/
package org.apache.ofbiz.base.test
-import org.apache.ofbiz.testtools.GroovyScriptAssert
+import org.apache.ofbiz.service.testtools.OFBizTestCase
/**
* Class validating groovy scripts test engine.
*/
-class SimpleTests extends GroovyScriptAssert {
+
+class SimpleTests extends OFBizTestCase {
+
+ SimpleTests(String name) {
+ super(name)
+ }
void testTrue() {
assert 1 + 1 == 2
@@ -38,7 +43,7 @@ class SimpleTests extends GroovyScriptAssert {
}
void testSecurity() {
- assert security
+ assert dispatcher.security
}
}
diff --git a/framework/base/testdef/basetests.xml
b/framework/base/testdef/basetests.xml
new file mode 100644
index 0000000000..661302cf02
--- /dev/null
+++ b/framework/base/testdef/basetests.xml
@@ -0,0 +1,26 @@
+<!--
+ 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.
+ -->
+
+<test-suite suite-name="basetests"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
+ <test-case case-name="basesimpletests">
+ <junit-test-suite class-name="org.apache.ofbiz.base.test.SimpleTests"/>
+ </test-case>
+</test-suite>
diff --git a/framework/service/servicedef/services_test_se.xml
b/framework/service/servicedef/services_test_se.xml
index abdd2a321a..b099d01f0d 100644
--- a/framework/service/servicedef/services_test_se.xml
+++ b/framework/service/servicedef/services_test_se.xml
@@ -198,20 +198,20 @@ under the License.
<!--call groovy engine service -->
<service name="testGroovyPingSuccess" engine="groovy"
-
location="component://service/src/test/groovy/org/apache/ofbizservice/test/TestServices.groovy"
invoke="testPingSuccess">
+
location="component://service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy"
invoke="testPingSuccess">
<attribute name="ping" mode="IN" type="String"/>
<attribute name="pong" mode="OUT" type="String"/>
</service>
<service name="testGroovyPingError" engine="groovy"
require-new-transaction="true"
-
location="component://service/src/test/groovy/org/apache/ofbizservice/test/TestServices.groovy"
invoke="testPingError">
+
location="component://service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy"
invoke="testPingError">
<implements service="testGroovyPingSuccess"/>
</service>
<service name="testGroovyPingSuccessWithDSLCall" engine="groovy"
-
location="component://service/src/test/groovy/org/apache/ofbizservice/test/TestServices.groovy"
invoke="testPingSuccessWithDSLCall">
+
location="component://service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy"
invoke="testPingSuccessWithDSLCall">
<implements service="testGroovyPingSuccess"/>
</service>
<service name="testGroovyPingErrorWithDSLCall" engine="groovy"
-
location="component://service/src/test/groovy/org/apache/ofbizservice/test/TestServices.groovy"
invoke="testPingErrorWithDSLCall">
+
location="component://service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy"
invoke="testPingErrorWithDSLCall">
<implements service="testGroovyPingSuccess"/>
</service>
</services>
diff --git
a/framework/service/src/main/groovy/org/apache/ofbiz/service/test/ServicePurgeTest.groovy
b/framework/service/src/main/groovy/org/apache/ofbiz/service/test/ServicePurgeTest.groovy
index 24ecb5f309..2efc1e2de6 100644
---
a/framework/service/src/main/groovy/org/apache/ofbiz/service/test/ServicePurgeTest.groovy
+++
b/framework/service/src/main/groovy/org/apache/ofbiz/service/test/ServicePurgeTest.groovy
@@ -22,12 +22,17 @@ import org.apache.ofbiz.base.util.UtilDateTime
import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.entity.util.EntityQuery
import org.apache.ofbiz.service.config.ServiceConfigUtil
-import org.apache.ofbiz.testtools.GroovyScriptAssert
-
-class ServicePurgeTest extends GroovyScriptAssert {
+import org.apache.ofbiz.service.testtools.OFBizTestCase
// ./gradlew "ofbiz --test component=service --test suitename=servicetests
--test case=service-purge-test"
+class ServicePurgeTest extends OFBizTestCase {
+
+ ServicePurgeTest(String name) {
+ super(name)
+ }
+
+
void testRuntimeDataIsCleanedAfterServicePurge() {
GenericValue sysUserLogin = delegator.findOne('UserLogin', true,
'userLoginId', 'system')
String jobId = delegator.getNextSeqId('JobSandbox')
diff --git
a/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
b/framework/service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy
similarity index 59%
copy from
framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
copy to
framework/service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy
index 8ca4ff0cd6..71a0a1799e 100644
---
a/framework/base/src/main/groovy/org/apache/ofbiz/base/test/SimpleTests.groovy
+++
b/framework/service/src/main/groovy/org/apache/ofbiz/service/test/TestServices.groovy
@@ -16,29 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.ofbiz.base.test
-import org.apache.ofbiz.testtools.GroovyScriptAssert
+package org.apache.ofbiz.service.test
-/**
- * Class validating groovy scripts test engine.
- */
-class SimpleTests extends GroovyScriptAssert {
+// Despite it's name, this class is not for test, it's only services
- void testTrue() {
- assert 1 + 1 == 2
- }
- void testDelegator() {
- assert delegator
+Map testPingSuccess() {
+ Map returnMap = success('Service result success')
+ if (parameters.ping) {
+ returnMap.pong = parameters.ping
}
+ return returnMap
+}
- void testDispatcher() {
- assert dispatcher
+Map testPingError() {
+ Map returnMap = error('Service result error')
+ if (parameters.ping) {
+ returnMap.pong = parameters.ping
}
+ return returnMap
+}
- void testSecurity() {
- assert security
- }
+Map testPingSuccessWithDSLCall() {
+ run service: 'testGroovyPingSuccess', with: parameters
+}
+Map testPingErrorWithDSLCall() {
+ run service: 'testGroovyPingError', with: parameters
}
diff --git
a/framework/service/src/main/java/org/apache/ofbiz/service/test/ServiceEngineTestPermissionServices.java
b/framework/service/src/main/java/org/apache/ofbiz/service/test/ServiceEngineTestPermissionServices.java
index 895fc41dc8..52b780f11a 100644
---
a/framework/service/src/main/java/org/apache/ofbiz/service/test/ServiceEngineTestPermissionServices.java
+++
b/framework/service/src/main/java/org/apache/ofbiz/service/test/ServiceEngineTestPermissionServices.java
@@ -19,14 +19,12 @@
package org.apache.ofbiz.service.test;
import java.util.Map;
+
import org.apache.ofbiz.service.DispatchContext;
import org.apache.ofbiz.service.ServiceUtil;
public class ServiceEngineTestPermissionServices {
- private static final String MODULE =
ServiceEngineTestPermissionServices.class.getName();
- private static final String RESOURCE = "ServiceErrorUiLabels";
-
public static Map<String, Object> genericTestService(DispatchContext dctx,
Map<String, ? extends Object> context) {
return ServiceUtil.returnSuccess();
}
diff --git a/framework/service/testdef/servicetests.xml
b/framework/service/testdef/servicetests.xml
index 3d5bafa869..6bd2b788e8 100644
--- a/framework/service/testdef/servicetests.xml
+++ b/framework/service/testdef/servicetests.xml
@@ -75,4 +75,7 @@ under the License.
<test-case case-name="service-permission-tests">
<junit-test-suite
class-name="org.apache.ofbiz.service.test.ServicePermissionTests"/>
</test-case>
+ <test-case case-name="service-purge-test">
+ <junit-test-suite
class-name="org.apache.ofbiz.service.test.ServicePurgeTest"/>
+ </test-case>
</test-suite>