This is an automated email from the ASF dual-hosted git repository.

ashishvijaywargiya pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 8555155a8 Restructure example component's test files and rename 
JUnit3-style test class (#372)
8555155a8 is described below

commit 8555155a8c6451ad57b28396c0a72b7d446b3438
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Fri Aug 21 21:39:15 2026 +0530

    Restructure example component's test files and rename JUnit3-style test 
class (#372)
---
 example/servicedef/services.xml                    |  62 ++++----
 .../ofbiz/example/ExampleTestRunServices.groovy    |   0
 .../test/{jupiter => }/ExampleJupiterTests.groovy  | 176 ++++++++++-----------
 ...leTests.groovy => ExampleOldJUnit3Tests.groovy} |   4 +-
 example/testdef/tests.xml                          |   6 +-
 5 files changed, 121 insertions(+), 127 deletions(-)

diff --git a/example/servicedef/services.xml b/example/servicedef/services.xml
index b52bbcca0..bdab03f87 100644
--- a/example/servicedef/services.xml
+++ b/example/servicedef/services.xml
@@ -146,37 +146,6 @@ under the License.
         <attribute name="successMessage" mode="IN" type="String" 
optional="true"></attribute>
     </service>
 
-    <!-- Test Run Services (component-scoped wrapper around 
framework/testtools) -->
-    <service name="runExampleTestSuite" engine="groovy" auth="true"
-             
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy"
-             invoke="runExampleTestSuite">
-        <description>Kicks off a testdef test-suite run asynchronously, scoped 
to the example
-            component only - see TestRunServices.runScopedTestSuite. Gated by 
the test.api.enabled
-            config flag and the TESTEXEC_ADMIN permission (checked inside the 
underlying service).
-            componentName is deliberately not an attribute here - the 
component is fixed, not
-            caller-suppliable. testMethodName optionally scopes the run to one
-            @Test/@ParameterizedTest method within the class testCaseName 
resolves to - requires
-            testCaseName, and only applies when it resolves to a 
jupiter-test-suite.</description>
-        <attribute name="suiteName" type="String" mode="IN" optional="false"/>
-        <attribute name="testCaseName" type="String" mode="IN" 
optional="true"/>
-        <attribute name="testMethodName" type="String" mode="IN" 
optional="true"/>
-        <attribute name="testParams" type="Map" mode="IN" optional="true"/>
-        <attribute name="runId" type="String" mode="OUT" optional="true"/>
-    </service>
-
-    <service name="getExampleTestRunStatus" engine="groovy" auth="true"
-             
location="component://example/src/main/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy"
-             invoke="getExampleTestRunStatus">
-        <description>Reads a runExampleTestSuite-triggered run's status, 
scoped to the example
-            component only - a runId belonging to another component's run is 
reported as
-            not-found, not a distinguishable "wrong component" error. See
-            TestRunServices.getScopedTestRunStatus.</description>
-        <attribute name="runId" type="String" mode="IN" optional="false"/>
-        <attribute name="status" type="String" mode="OUT" optional="true"/>
-        <attribute name="componentName" type="String" mode="OUT" 
optional="true"/>
-        <attribute name="resultSummary" type="Map" mode="OUT" optional="true"/>
-    </service>
-
     <!-- ExampleType services -->
     <service name="createExampleType" default-entity-name="ExampleType" 
engine="entity-auto" invoke="create" auth="true">
         <description>Create a record of ExampleType</description>
@@ -209,4 +178,35 @@ under the License.
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
 
+    <!-- Test Run Services (component-scoped wrapper around 
framework/testtools) -->
+    <service name="runExampleTestSuite" engine="groovy" auth="true"
+             
location="component://example/src/test/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy"
+             invoke="runExampleTestSuite">
+        <description>Kicks off a testdef test-suite run asynchronously, scoped 
to the example
+            component only - see TestRunServices.runScopedTestSuite. Gated by 
the test.api.enabled
+            config flag and the TESTEXEC_ADMIN permission (checked inside the 
underlying service).
+            componentName is deliberately not an attribute here - the 
component is fixed, not
+            caller-suppliable. testMethodName optionally scopes the run to one
+            @Test/@ParameterizedTest method within the class testCaseName 
resolves to - requires
+            testCaseName, and only applies when it resolves to a 
jupiter-test-suite.</description>
+        <attribute name="suiteName" type="String" mode="IN" optional="false"/>
+        <attribute name="testCaseName" type="String" mode="IN" 
optional="true"/>
+        <attribute name="testMethodName" type="String" mode="IN" 
optional="true"/>
+        <attribute name="testParams" type="Map" mode="IN" optional="true"/>
+        <attribute name="runId" type="String" mode="OUT" optional="true"/>
+    </service>
+
+    <service name="getExampleTestRunStatus" engine="groovy" auth="true"
+             
location="component://example/src/test/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy"
+             invoke="getExampleTestRunStatus">
+        <description>Reads a runExampleTestSuite-triggered run's status, 
scoped to the example
+            component only - a runId belonging to another component's run is 
reported as
+            not-found, not a distinguishable "wrong component" error. See
+            TestRunServices.getScopedTestRunStatus.</description>
+        <attribute name="runId" type="String" mode="IN" optional="false"/>
+        <attribute name="status" type="String" mode="OUT" optional="true"/>
+        <attribute name="componentName" type="String" mode="OUT" 
optional="true"/>
+        <attribute name="resultSummary" type="Map" mode="OUT" optional="true"/>
+    </service>
+
 </services>
diff --git 
a/example/src/main/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy
 
b/example/src/test/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy
similarity index 100%
rename from 
example/src/main/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy
rename to 
example/src/test/groovy/org/apache/ofbiz/example/ExampleTestRunServices.groovy
diff --git 
a/example/src/test/groovy/org/apache/ofbiz/example/test/jupiter/ExampleJupiterTests.groovy
 
b/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleJupiterTests.groovy
similarity index 77%
rename from 
example/src/test/groovy/org/apache/ofbiz/example/test/jupiter/ExampleJupiterTests.groovy
rename to 
example/src/test/groovy/org/apache/ofbiz/example/test/ExampleJupiterTests.groovy
index cbd812638..27a85e957 100644
--- 
a/example/src/test/groovy/org/apache/ofbiz/example/test/jupiter/ExampleJupiterTests.groovy
+++ 
b/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleJupiterTests.groovy
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.ofbiz.example.test.jupiter
+package org.apache.ofbiz.example.test
 
 import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.service.ServiceUtil
@@ -34,7 +34,7 @@ import org.junit.jupiter.params.provider.MethodSource
 
 /**
  * Jupiter test-cases run through testdef's jupiter-test-suite element (see 
plugins/example/testdef/tests.xml),
- * side-by-side with org.apache.ofbiz.example.test.ExampleTests in the same 
test-suite. Runs inside the full
+ * side-by-side with org.apache.ofbiz.example.test.ExampleOldJUnit3Tests in 
the same test-suite. Runs inside the full
  * ofbiz --test container, so JupiterTestExtension injects the suite's own 
Delegator/LocalDispatcher.
  * Implementing JupiterTestHelper needs no field declarations, yet Groovy's 
getter-as-property syntax still
  * exposes them as bare delegator/dispatcher (backed by JupiterTestHelper's 
getDelegator()/getDispatcher()),
@@ -51,8 +51,64 @@ class ExampleJupiterTests implements JupiterTestHelper {
     @Test
     @Order(1)
     void shouldCreateExample() {
-        GenericValue example = createAndAssertExample('Test Example - 
Integration')
+
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String exampleTypeId = testParams.exampleTypeId ?: 'CONTRIVED'
+        String exampleName = testParams.exampleName ?: 'Test Example - 
Integration'
+        String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
+
+        Map<String, Object> result = dispatcher.runSync('createExample', [
+                exampleTypeId: exampleTypeId,
+                exampleName: exampleName,
+                statusId: statusId,
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(result)
+
+        GenericValue example = from('Example').where('exampleId', 
result.exampleId).queryOne()
+        assert example != null
+        Assertions.assertEquals(exampleTypeId, example.exampleTypeId)
+        Assertions.assertEquals(exampleName, example.exampleName)
+        Assertions.assertEquals(statusId, example.statusId)
+    }
+
+    @Test
+    @Order(6)
+    void shouldUpdateExample() {
+
+        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
+
+        String exampleTypeId = testParams.exampleTypeId ?: 'CONTRIVED'
+        String exampleName = testParams.exampleName ?: 'Test Example - Before 
Update'
+        String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
+
+        Map<String, Object> createResult = dispatcher.runSync('createExample', 
[
+                exampleTypeId: exampleTypeId,
+                exampleName: exampleName,
+                statusId: statusId,
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(createResult)
+        String exampleId = createResult.exampleId
+
+        String updatedExampleName = testParams.updatedExampleName ?: 'Test 
Example - After Update'
+        String updatedStatusId = testParams.updatedStatusId ?: 'EXST_DEFINED'
+
+        Map<String, Object> updateResult = dispatcher.runSync('updateExample', 
[
+                exampleId: exampleId,
+                exampleName: updatedExampleName,
+                statusId: updatedStatusId,
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(updateResult)
+        assert updateResult.oldStatusId == statusId
+
+        GenericValue example = from('Example').where('exampleId', 
exampleId).queryOne()
         assert example != null
+        assert example.exampleTypeId == exampleTypeId
+        assert example.exampleName == updatedExampleName
+        assert example.statusId == updatedStatusId
     }
 
     @ParameterizedTest(name = '[{index}] exampleTypeId={0}')
@@ -68,7 +124,7 @@ class ExampleJupiterTests implements JupiterTestHelper {
         // exampleTypeId is deliberately left CSV-driven, not 
testParams-driven - that's the one
         // value this method exists to vary across invocations. statusId isn't 
varied by the CSV
         // source, so it's the one field here that can take a caller override 
the same way
-        // shouldCreateExample/shouldCreateExampleWithParams do.
+        // shouldCreateExample does.
         String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
         Map<String, Object> result = dispatcher.runSync('createExample', [
                 exampleTypeId: exampleTypeId,
@@ -79,13 +135,35 @@ class ExampleJupiterTests implements JupiterTestHelper {
         assert ServiceUtil.isSuccess(result)
     }
 
+    // This method will not be executed and will remain disabled since it is 
annotated with @Disabled.
     @Disabled('OFBIZ-XXXXX: sample only - demonstrates a documented, 
reportable skip; not a real defect')
     @Test
     @Order(3)
-    void shouldUpdateExampleUnderConcurrentLoad() {
+    void shouldDeleteExample() {
+
         GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
-        Map<String, Object> result = dispatcher.runSync('updateExample', 
[exampleId: 'TestExampleUpdate', userLogin: userLogin])
-        assert ServiceUtil.isSuccess(result)
+
+        String exampleTypeId = testParams.exampleTypeId ?: 'CONTRIVED'
+        String exampleName = testParams.exampleName ?: 'Test Example - Before 
Delete'
+        String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
+
+        Map<String, Object> createResult = dispatcher.runSync('createExample', 
[
+                exampleTypeId: exampleTypeId,
+                exampleName: exampleName,
+                statusId: statusId,
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(createResult)
+        String exampleId = createResult.exampleId
+
+        Map<String, Object> deleteResult = dispatcher.runSync('deleteExample', 
[
+                exampleId: exampleId,
+                userLogin: userLogin
+        ])
+        assert ServiceUtil.isSuccess(deleteResult)
+
+        GenericValue example = from('Example').where('exampleId', 
exampleId).queryOne()
+        assert example == null
     }
 
     @ParameterizedTest(name = '[{index}] {0}')
@@ -116,59 +194,6 @@ class ExampleJupiterTests implements JupiterTestHelper {
         }
     }
 
-    @Test
-    @Order(5)
-    void shouldCreateExampleWithParams() {
-        GenericValue example = createAndAssertExample('Test Example - Default')
-        assert example != null
-    }
-
-    @Test
-    @Order(6)
-    void shouldUpdateExample() {
-        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
-        // Initial-state fields reuse the same testParams keys 
shouldCreateExample uses - both tests
-        // create a fresh Example the same way, so sharing key names here is 
harmless (each test's
-        // record is independent). The post-update target fields use their 
own, distinct keys
-        // (updatedExampleName/updatedStatusId) - those can't share names with 
the initial-state keys
-        // above, or one testParams map couldn't set a different "before" and 
"after" value in the
-        // same call.
-        String exampleTypeId = testParams.exampleTypeId ?: 'CONTRIVED'
-        String exampleName = testParams.exampleName ?: 'Test Example - Before 
Update'
-        String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
-
-        Map<String, Object> createResult = dispatcher.runSync('createExample', 
[
-                exampleTypeId: exampleTypeId,
-                exampleName: exampleName,
-                statusId: statusId,
-                userLogin: userLogin
-        ])
-        assert ServiceUtil.isSuccess(createResult)
-        String exampleId = createResult.exampleId
-
-        // EXST_APPROVED isn't reachable directly from EXST_IN_DESIGN per 
ExampleDemoData.xml's
-        // StatusValidChange rows (IN_DESIGN -> DEFINED -> APPROVED) - 
EXST_DEFINED is the default
-        // here because it's the one status updateExample can always reach 
from the default initial
-        // statusId above in a single call.
-        String updatedExampleName = testParams.updatedExampleName ?: 'Test 
Example - After Update'
-        String updatedStatusId = testParams.updatedStatusId ?: 'EXST_DEFINED'
-
-        Map<String, Object> updateResult = dispatcher.runSync('updateExample', 
[
-                exampleId: exampleId,
-                exampleName: updatedExampleName,
-                statusId: updatedStatusId,
-                userLogin: userLogin
-        ])
-        assert ServiceUtil.isSuccess(updateResult)
-        assert updateResult.oldStatusId == statusId
-
-        GenericValue example = from('Example').where('exampleId', 
exampleId).queryOne()
-        assert example != null
-        assert example.exampleTypeId == exampleTypeId
-        assert example.exampleName == updatedExampleName
-        assert example.statusId == updatedStatusId
-    }
-
     @SuppressWarnings('UnusedPrivateMethod')
     private static List<Arguments> exampleCreationCases() {
         [
@@ -181,35 +206,4 @@ class ExampleJupiterTests implements JupiterTestHelper {
         ]
     }
 
-    /**
-     * Creates an Example from testParams-driven 
exampleTypeId/exampleName/statusId (each falling
-     * back to a default) and asserts the createExample service succeeded and 
that the persisted
-     * record matches the resolved values - the exact create+assert sequence 
shouldCreateExample()
-     * and shouldCreateExampleWithParams() both perform, differing only in 
exampleName's default
-     * text, factored out here to remove that duplication.
-     * @param defaultExampleName the exampleName to use when testParams 
doesn't override it
-     * @return the created, already-asserted Example
-     */
-    private GenericValue createAndAssertExample(String defaultExampleName) {
-        GenericValue userLogin = delegator.findOne('UserLogin', [userLoginId: 
'system'], false)
-        String exampleTypeId = testParams.exampleTypeId ?: 'CONTRIVED'
-        String exampleName = testParams.exampleName ?: defaultExampleName
-        String statusId = testParams.statusId ?: 'EXST_IN_DESIGN'
-
-        Map<String, Object> result = dispatcher.runSync('createExample', [
-                exampleTypeId: exampleTypeId,
-                exampleName: exampleName,
-                statusId: statusId,
-                userLogin: userLogin
-        ])
-        assert ServiceUtil.isSuccess(result)
-
-        GenericValue example = from('Example').where('exampleId', 
result.exampleId).queryOne()
-        assert example != null
-        Assertions.assertEquals(exampleTypeId, example.exampleTypeId)
-        Assertions.assertEquals(exampleName, example.exampleName)
-        Assertions.assertEquals(statusId, example.statusId)
-        example
-    }
-
 }
diff --git 
a/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleTests.groovy 
b/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleOldJUnit3Tests.groovy
similarity index 97%
rename from 
example/src/test/groovy/org/apache/ofbiz/example/test/ExampleTests.groovy
rename to 
example/src/test/groovy/org/apache/ofbiz/example/test/ExampleOldJUnit3Tests.groovy
index eb71ad660..59f49c0e0 100644
--- a/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleTests.groovy
+++ 
b/example/src/test/groovy/org/apache/ofbiz/example/test/ExampleOldJUnit3Tests.groovy
@@ -24,9 +24,9 @@ import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.service.ServiceUtil
 import org.apache.ofbiz.service.testtools.OFBizTestCase
 
-class ExampleTests extends OFBizTestCase {
+class ExampleOldJUnit3Tests extends OFBizTestCase {
 
-    ExampleTests(String name) {
+    ExampleOldJUnit3Tests(String name) {
         super(name)
     }
 
diff --git a/example/testdef/tests.xml b/example/testdef/tests.xml
index b2189bd68..d0f090bd4 100644
--- a/example/testdef/tests.xml
+++ b/example/testdef/tests.xml
@@ -30,11 +30,11 @@ under the License.
         <entity-xml action="load" 
entity-xml-url="component://example/testdef/data/ExampleTestData.xml"/>
     </test-case>
 
-    <test-case case-name="example-tests-groovy">
-        <junit-test-suite 
class-name="org.apache.ofbiz.example.test.ExampleTests"/>
+    <test-case case-name="example-tests-junit3">
+        <junit-test-suite 
class-name="org.apache.ofbiz.example.test.ExampleOldJUnit3Tests"/>
     </test-case>
 
     <test-case case-name="example-tests-jupiter">
-        <jupiter-test-suite 
class-name="org.apache.ofbiz.example.test.jupiter.ExampleJupiterTests"/>
+        <jupiter-test-suite 
class-name="org.apache.ofbiz.example.test.ExampleJupiterTests"/>
     </test-case>
 </test-suite>

Reply via email to