Skip to content

Migrate remaining MockMvc tests to RestTestClient - #702

Closed
rjayasinghe wants to merge 1 commit into
mainfrom
migrate-mockmvc-to-resttestclient
Closed

Migrate remaining MockMvc tests to RestTestClient#702
rjayasinghe wants to merge 1 commit into
mainfrom
migrate-mockmvc-to-resttestclient

Conversation

@rjayasinghe

Copy link
Copy Markdown
Contributor

What

Migrates the two remaining MockMvc-based tests to RestTestClient, matching the pattern already used in CatalogServiceITest:

  • srv/.../GenreHierarchyTest.java
  • integration-tests/.../FeatureTogglesIT.java

RestTestClient is now the only servlet test client used across the integration/service tests; no more MockMvc usage remains.

Changes

  • @AutoConfigureMockMvc@AutoConfigureRestTestClient, MockMvcRestTestClient
  • client.perform(get(uri))client.get().uri(uri).exchange()
  • .andExpect(status().isOk()).expectStatus().isOk()
  • .andExpect(jsonPath(p).value(v)).expectBody().jsonPath(p).isEqualTo(v) (works for both string and numeric values, incl. the $count scalar)
  • .andExpect(jsonPath(p).doesNotExist()).jsonPath(p).doesNotExist()
  • Hamcrest containsString matchers → AssertJ value(Class, Consumer) (consistent with the reference test)
  • Dropped now-unnecessary throws Exception; kept UriComponentsBuilder/URI handling in filterExpandLevels

No production code changed.

Testing

  • GenreHierarchyTest11/11 pass
  • FeatureTogglesIT3/3 pass (verified with the MTX sidecar running on localhost:4005, as required by the test's existing precondition)

Convert GenreHierarchyTest and FeatureTogglesIT from MockMvc to
RestTestClient, matching the pattern already used in CatalogServiceITest:

- @AutoConfigureMockMvc -> @AutoConfigureRestTestClient
- MockMvc -> RestTestClient
- client.perform(get(uri)) -> client.get().uri(uri).exchange()
- .andExpect(status().isOk()) -> .expectStatus().isOk()
- jsonPath(p).value(v) -> .expectBody().jsonPath(p).isEqualTo(v)
- jsonPath(p).doesNotExist() -> .jsonPath(p).doesNotExist()
- Hamcrest containsString matchers -> AssertJ value(Class, Consumer)

RestTestClient is now the only servlet test client used across the
integration/service tests.
@rjayasinghe

Copy link
Copy Markdown
Contributor Author

I understood that we want to keep both, MockMVC and RestTestClient in the sample. Thus, I close this one.

@rjayasinghe
rjayasinghe deleted the migrate-mockmvc-to-resttestclient branch July 29, 2026 13:18
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