test(viewtools): add raw() VTL coverage for aggregations (#36026)#36093
test(viewtools): add raw() VTL coverage for aggregations (#36026)#36093fabrizzio-dotCMS wants to merge 1 commit into
Conversation
ContentSearchToolTest only exercised $estool.search() through the Velocity engine; raw() was covered at the Java API level only. This adds rawVtl_rendersTreeAndFlatAggregations, driving $estool.raw($esQuery) through VelocityUtil.eval and asserting both response surfaces render real data: - tree walk: $tree.content_types.buckets -> getDocCount() -> nested top_content top_hits -> $hit.id - flat map: $flat.content_types iterated directly as List<AggregationBucket> Documents the record-accessor gotcha that motivated the test: raw() returns a ContentSearchResponse record whose accessors are aggregations() / aggregationTree() (no get* prefix), which Velocity's property syntax cannot resolve, so the template must call them with explicit () — unlike search()'s ContentSearchResults, which exposes bean getters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @fabrizzio-dotCMS's task in 1m 33s —— View job Code Review
Clean test-only change. A few things worth noting: 1. Weak first assertion (line 332) assertTrue("Aggregation data should be present in the response",
output.contains("content_types"));This passes trivially because 2. Javadoc/template mismatch The
But the actual template uses 3. Silent failure path in VTL if sub-agg is missing #set($topHits = $group.getAggregations().get("top_content"))
#foreach($hit in $topHits.getHits().getHits())If Not flagged: The record accessor workaround is correctly implemented and well-documented. The data setup in |
Proposed Changes
Follow-up test coverage for #36026. The fix for that issue restored a vendor-neutral aggregation tree so existing VTL templates walking
$results.aggregationskeep working after the ES→OS migration.ContentSearchToolTestalready verified this through Velocity for$estool.search(...), and verified$estool.raw(...)only at the Java API level — there was no test drivingraw()through the Velocity engine.This PR adds
rawVtl_rendersTreeAndFlatAggregations, which evaluates#set($results = $estool.raw($esQuery))throughVelocityUtil.evaland asserts both response surfaces render real data:$tree.content_types.buckets→getKeyAsString()/getDocCount()→ nestedtop_contenttop_hits→$hit.id(mirrors thesearch()customer template).$flat.content_typesiterated directly as aList<AggregationBucket>(the raw-specific shape that differs fromsearch()).Record-accessor gotcha (documented in the test)
raw()returns aContentSearchResponserecord, whose accessors areaggregations()/aggregationTree()— there are noget*methods. Velocity's property syntax ($results.aggregations) only resolvesgetX()/isX()/public fields, so on a record it silently yieldsnull. The template therefore calls them with explicit method syntax ($results.aggregationTree()), then stays property-style downstream becauseAggregation's components are namedgetBuckets/getHitsandAggregationBucketexposes bean getters. This contrasts withsearch(), which returns aContentSearchResultsclass with real bean getters.Testing
Run against a live integration environment (PostgreSQL + OpenSearch):
All 5 tests pass (4 pre-existing + the new one). Test-only change; no production code touched.
Closes #36026
🤖 Generated with Claude Code