Skip to content

WW-3353 fix(junit): make StrutsRestTestCase work against a REST/Convention app - #1956

Merged
lukaszlenart merged 1 commit into
mainfrom
fix/WW-3353-rest-test-case
Sep 16, 2026
Merged

lukaszlenart merged 1 commit into
mainfrom
fix/WW-3353-rest-test-case

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

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:

  1. initServletMockObjects() order — the MockServletContext was built before ConventionPluginResourceLoader was 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.
  2. Missing spring-webspring-test's MockHttpServletResponse needs org.springframework.http.MediaType, and the plugin only reached spring-web through its optional struts2-spring-plugin dependency. A project following the docs (Spring plugin only for Spring-managed actions) got NoClassDefFoundError on the first test. Declared directly; the version is BOM-managed and already resolved transitively elsewhere.

Adds OrdersControllerRestTestCaseTest in apps/rest-showcase — the first coverage of StrutsRestTestCase — executing GET /orders/3 through the proxy (id bound from the path, Convention result resolved) and rendering /orders/3.json. The showcase POM gets the junit plugin at test scope and the servlet/JSP APIs at provided scope, as apps/showcase already declares.

On the ticket's original symptom ("/orders/3 doesn't call setId"): the attached test called action.show() directly without proxy.execute(), so no interceptor ran; with execute() 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

…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
lukaszlenart marked this pull request as ready for review September 16, 2026 07:28
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@lukaszlenart
lukaszlenart merged commit 9831e0f into main Sep 16, 2026
12 of 14 checks passed
@lukaszlenart
lukaszlenart deleted the fix/WW-3353-rest-test-case branch September 16, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant