REST API Support for Running and Monitoring OFBiz Test Cases(example component sample code) - #370
Merged
ashishvijaywargiya merged 13 commits intoAug 20, 2026
Conversation
- example.rest.xml: runTestSuite accepts an optional componentName and, when omitted, runs suites from every registered component in the installation, not just example's. Reword the TestRunResource description so a reader doesn't underestimate the endpoint's reach (still permission-gated, this is a documentation accuracy fix, not a security fix). - ExampleJupiterTests.groovy: shouldCreateExampleWithParams() used Assertions.assertFalse(ServiceUtil.isError(result)) and delegator.findOne(...), inconsistent with the file's other four methods (assert ServiceUtil.isSuccess(result) / from(...).where(...).queryOne()). Also assertFalse(isError(...)) is weaker than assert isSuccess(...): a responseMessage of neither 'error' nor 'success' would pass the former without actually succeeding. Aligned to match the file's established idiom; the rest of the method is unchanged.
…e.rest.xml The description was split across two source lines with continuation indentation; XML attribute-value normalization collapses the newline but not the ~18 spaces of leading indent, leaving a long run of literal spaces mid-sentence in the parsed value (visible in generated docs). Put it back on one line.
…teExampleAcrossTypes shouldCreateExample now reads exampleTypeId/exampleName/statusId from testParameters with the same inline-default pattern shouldCreateExampleWithParams already uses. shouldCreateExampleAcrossTypes keeps exampleTypeId CSV-driven (the value it exists to vary) but now reads statusId from testParameters, since that field isn't varied by the CSV source. shouldCreateExampleAcrossTypesAndStatuses deliberately left untouched - every field there is already varied per-row by its MethodSource table, including two rows that pass null exampleTypeId/exampleName specifically to test required-field validation; a testParameters fallback would silently replace those nulls and break what the test verifies.
Matches the JupiterTestHelper.getTestParams() rename in ofbiz-trunk (same feature, companion commit) - one name for the concept everywhere, matching the wire-level runTestSuite testParams attribute.
Creates an Example, then updates its exampleName/statusId, and verifies both the update took effect and the service's oldStatusId OUT attribute correctly reports the pre-update status. Initial-state fields (exampleTypeId/exampleName/statusId) read from testParams using the same key names shouldCreateExample already uses - safe to share since each test creates its own independent record. The post-update target fields use distinct keys (updatedExampleName/ updatedStatusId) so a single testParams map can set a different 'before' and 'after' value in the same call.
Replaces the java engine wrapper with engine=groovy, removing the compiled class in favor of a plain groovy script. Same behavior: componentName stays a fixed literal in each method, not caller- suppliable.
…and shouldCreateExampleWithParams Both methods built userLogin, resolved the same three testParams fields, called createExample, and asserted the same way - factored into a shared createAndAssertExample(defaultExampleName) helper. Fixes the SonarCloud duplicated-lines quality gate failure on PR apache#370.
|
ashishvijaywargiya
added a commit
that referenced
this pull request
Aug 20, 2026
…tion (#371) ### Problem Trunk CI (`ofbizTrunkFrameworkPlugins` builder, [build 1756](https://ci2.apache.org/#/builders/46/builds/1756)) started failing right after the REST API test-cases-api-support merge (#370), on two independent issues in `ExampleJupiterTests.groovy`: 1. **`check` step** — `codenarcTest` failed with 4 violations (2 priority-2, 2 priority-3), exceeding the allowed threshold: - `shouldCreateExample()` / `shouldCreateExampleWithParams()` — flagged by `JUnitTestMethodWithoutAssert` because they only assert indirectly, through the private `createAndAssertExample()` helper - `createAndAssertExample(...)` — wrong indentation (`Indentation` rule) - `exampleCreationCases()` — private static method declared after a private instance method (`StaticMethodsBeforeInstanceMethods` rule) 2. **`testIntegration` step** — `shouldUpdateExample()` asserted a direct `EXST_IN_DESIGN -> EXST_APPROVED` status update, which isn't a valid transition per `ExampleDemoData.xml`'s `StatusValidChange` rows (the valid path is `IN_DESIGN -> DEFINED -> APPROVED`), so `updateExample` correctly errored and the assertion failed. ### Fix - Added a direct assert in `shouldCreateExample()` / `shouldCreateExampleWithParams()` on the returned `Example` - Fixed `createAndAssertExample`'s indentation - Reordered `exampleCreationCases()` before `createAndAssertExample()` - Changed `shouldUpdateExample()`'s default `updatedStatusId` from `EXST_APPROVED` to `EXST_DEFINED`, a transition that's actually reachable from the default initial `EXST_IN_DESIGN` status in one call ### Verification - `./gradlew codenarcTest` passes (previously failed with the exact violations CI reported) - `./gradlew compileTestGroovy` compiles clean - Confirmed `EXST_IN_DESIGN -> EXST_DEFINED` is a valid transition by inspecting `StatusValidChange` seed data in `ExampleDemoData.xml`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Pushing the sample code from plugins->example component, this will help others to see the patterns like how we can enable rest support for other component's test cases.
ofbiz-framework PR:
apache/ofbiz-framework#1690