私のコントローラーは:
import rx.Single;
...
@GetMapping
Single<List<MyType>> fetchFromDB() {
return Single
.fromCallable(() -> dao.fetch())
.subscribeOn(Schedulers.io());
}
そしてそれは完璧に機能します。しかし、私はそれをテストすることはできません。私は試した:
MvcResult asyncResult = mvc.perform(get("/")).andReturn()
String result = mvc
.perform(asyncDispatch(asyncResult))
.andReturn().getResponse().getContentAsString()
しかし、それは失敗します:
java.lang.IllegalStateException: Async result for handler [rx.Single<java.util.List<MyType>> MyController.fetchFromDB()] was not set during the specified timeToWait=-1
at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:145)
at org.springframework.test.web.servlet.DefaultMvcResult.getAsyncResult(DefaultMvcResult.java:121)
at org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch(MockMvcRequestBuilders.java:246)
at MyControllerSpec.should fetch from db...
だから:rx.Single
春のmvcでテストする方法は?
私は答えを見つけました。mockMvcオブジェクトを作成するときに、次のハンドラーを追加しますSingle
。
return MockMvcBuilders.standaloneSetup(controller)
.setCustomReturnValueHandlers(new SingleReturnValueHandler())
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加