WW-3353 fix(junit): make StrutsRestTestCase work against a REST/Convention app - #1956
Merged
Merged
Conversation
…ntion app
StrutsRestTestCase could not run a REST action to completion:
- initServletMockObjects() built the MockServletContext before
assigning ConventionPluginResourceLoader, so the loader was a dead
assignment and Convention could not resolve results under
/WEB-INF/content ("No result defined for action ... and result show").
- spring-test's MockHttpServletResponse needs spring-web, which the
plugin only reached through its optional struts2-spring-plugin
dependency; a project without the Spring plugin failed with
NoClassDefFoundError: org/springframework/http/MediaType.
Adds the first test of StrutsRestTestCase, in rest-showcase, executing
GET /orders/3 through the proxy and rendering /orders/3.json. The
showcase gets the junit plugin at test scope and the servlet/JSP APIs
at provided scope, as apps/showcase already declares.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lukaszlenart
marked this pull request as ready for review
September 16, 2026 07:28
|
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.


Fixes WW-3353
StrutsRestTestCase(added by WW-4549 as the answer to this ticket) has never had a test and could not actually run a REST action to completion. Two defects, each watched failing before the fix:initServletMockObjects()order — theMockServletContextwas built beforeConventionPluginResourceLoaderwas assigned, so the loader was a dead assignment and Convention could not resolve results under/WEB-INF/content:No result defined for action org.demo.rest.example.OrdersController and result show. Creating the loader first fixes it.spring-web—spring-test'sMockHttpServletResponseneedsorg.springframework.http.MediaType, and the plugin only reachedspring-webthrough its optionalstruts2-spring-plugindependency. A project following the docs (Spring plugin only for Spring-managed actions) gotNoClassDefFoundErroron the first test. Declared directly; the version is BOM-managed and already resolved transitively elsewhere.Adds
OrdersControllerRestTestCaseTestinapps/rest-showcase— the first coverage ofStrutsRestTestCase— executingGET /orders/3through the proxy (id bound from the path, Convention result resolved) and rendering/orders/3.json. The showcase POM gets the junit plugin attestscope and the servlet/JSP APIs atprovidedscope, asapps/showcasealready declares.On the ticket's original symptom ("
/orders/3doesn't callsetId"): the attached test calledaction.show()directly withoutproxy.execute(), so no interceptor ran; withexecute()the id binds even on the plain test case. The title claim was still true, for the two reasons above.Verified:
mvn test -pl apps/rest-showcase -Dtest=OrdersControllerRestTestCaseTest(2/2) and the junit plugin's own suite (12/12).🤖 Generated with Claude Code