Skip to content

Enum PathVariable is case sensitive in UnitTest (WebTestClient) #43939

@andreas-ajaib

Description

@andreas-ajaib

For context, I have been trying to find the resolution outside, but cannot find any.

So, I have a controller with path /api/{enum}/something. This path variable is mapped to some enum. Now, I want to create a unit test using WebTestClient something like below.

@SpringJUnitConfig({SomethingController.class})
@WebFluxTest(controllers = SomethingController.class)
class SomethingControllerTest {

  @Autowired
  private WebTestClient client;

  @Nested
  class SubTest {

    @Test
    void test() throws Exception {
      // arrange
      final var request = new Request();

      // act
      client.post()
          .uri("/api/{enum}/something", "ENUMA") // if I put upper case here. it's working. if I put lower case "enuma", it's not working.
          .contentType(MediaType.APPLICATION_JSON)
          .bodyValue(request)
          .exchange()
          .expectStatus().isOk();
    }
  }
}

If I put upper case in the path variable. it's working. If I put lower case, it's not working. It's inconsistent with the real/actual running. When I run the app, it can accept the lower case enum.

Version:

  • Spring Boot 3.3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions