0

@RestControllerコントローラーメソッドの引数の1つがどこにありますかLocale

@RequestMapping("/{id}")
public Survey getSurvey( @PathVariable("id") SurveyId surveyId, 
                         Locale locale ) { ... }

Accept-Languageヘッダーを設定してロケールを切り替えることができる作業統合テスト (RestAssured を使用) があります。

Spring REST ドキュメントも使用して、これを文書化したいと思います。この場合 (MockMvc を使用して) ヘッダーを設定しても機能しません。

私のテストは次のようなものです:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration
@WebAppConfiguration
public void SurveyControllerDocumentation {

    // Test methods here
    ...

    // Application context for documentation test
    @Configuration
    @EnableAutoConfiguration
    public static class TestConfiguration {
        @Bean
        public SurveyController controller(MessageSource messageSource) {
            return new SurveyController(userService(), messageSource, surveyService());
        }

        @Bean
        public UserService userService() {
            return mock(UserService.class);
        }

        @Bean
        public SurveyService surveyService() {
            return mock(SurveyService.class);
        }

        @Bean
        public CustomEditorsControllerAdvice customEditorsControllerAdvice() {
            return new CustomEditorsControllerAdvice();
        }

        @Bean
        public RestResponseEntityExceptionHandler exceptionHandler() {
            return new RestResponseEntityExceptionHandler();
        }
    }
}

ロケール インジェクションを行うテスト コンテキストに明示的に追加する必要がある Bean はありますか?

Spring Boot 1.3.3 (Spring 4.2.5 を含む) を使用しています。

4

1 に答える 1