jamesfredley opened a new pull request, #15441:
URL: https://github.com/apache/grails-core/pull/15441
## Summary
Tests were calling `GormEnhancer.findStaticApi()`, `findInstanceApi()`, and
`findValidationApi()` to reach into GORM internals directly. This PR replaces
all such usages with the same public APIs an end user would call.
## Changes
| File | Before | After |
|------|--------|-------|
| `WhereQueryConnectionRoutingSpec` | `GormEnhancer.findStaticApi(Domain,
connection)` for tx/list | `Domain."${connectionName}"` named-datasource
property + `item.save()`/`item.delete()` |
| `FooIntegrationSpec` / `BarIntegrationSpec` |
`findStaticApi(Foo).datastore` | `Foo.withNewSession { it.datastore instanceof
... }` |
| `SaveWithFailOnErrorDefaultSpec` | Mutate internal
`GormInstanceApi.failOnError` field | Test per-call `save(failOnError:
true/false)` behaviour |
| `DeepValidateWithSaveSpec` | `findInstanceApi` + mock `GormValidateable` |
Real entity + `entity.save(deepValidate: true/false)` |
| `DataServiceMultiTenantMultiDataSourceSpec` (test) | `findStaticApi`
not-null assertion | Functional save/count via `metricService` |
| `DataServiceMultiTenantMultiDataSourceSpec` (`MetricService`) |
`findStaticApi(Metric, 'analytics')` in service body |
`Metric.executeQuery/executeUpdate` (transaction already routes to `analytics`)
|
| `DataServiceMultiDataSourceSpec` | `findStaticApi(Product, 'books')` for
setup/count/HQL | `productService.deleteAll()` + `@Query` methods on
`ProductService` |
| `ValidationSpec` (neo4j) | `findValidationApi(cls).validator = null` |
`session.mappingContext.addEntityValidator(entity, null)` |
## Verification
All affected tests pass:
- `SaveWithFailOnErrorDefaultSpec` — 4 tests PASSED
- `DeepValidateWithSaveSpec` — 2 tests PASSED
- `DataServiceMultiDataSourceSpec` — 20 tests PASSED
- `DataServiceMultiTenantMultiDataSourceSpec` — 7 tests PASSED
The `grails-data-graphql` and `grails-data-neo4j` modules are not active in
the current build (not yet updated for Grails 7); their files are cleaned up
but cannot be run locally.
Relates to the principle added in #15440: tests should use only public APIs
as an end user would.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]