vendredi 21 octobre 2016

spring-mvc: how to test Rx responses with mockMvc?

my controller is:

import rx.Single;
...

@GetMapping
Single<List<MyType>> fetchFromDB() {
        return Single
                .fromCallable(() -> dao.fetch())
                .subscribeOn(Schedulers.io());
}

and it works perfectly. but i can't tests it. i tried:

 MvcResult asyncResult = mvc.perform(get("/")).andReturn()

 String result = mvc
                    .perform(asyncDispatch(asyncResult))
                    .andReturn().getResponse().getContentAsString()

but it fails with:

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...

so: how to test rx.Single with spring mvc?

Aucun commentaire:

Enregistrer un commentaire