spring mvc servlet 3 async response no database result in test -


i'm testing new servlet 3 asynchronous requests in new project , stuck while testing controller.

i have controller method this:

@requestmapping(value = "/thumbnails", method = requestmethod.get) public callable<responseentity<list<thumbnail>>> getallthumbnails() {     //at point results repository     return () -> {         //at point don't results         final list<thumbnail> thumbnails = thumbnailrepository.findall();         return responseentity.ok(thumbnails);     }; } 

and corresponding test this:

@test @transactional public void testgetallthumbnails() throws exception {     thumbnailrepository.saveandflush(thumbnail);      final mvcresult mvcresult = restthumbnailmockmvc.perform(get("/test/thumbnails"))                                                     .andexpect(request().asyncstarted())                                                     .andexpect(request().asyncresult(instanceof(responseentity.class)))                                                     .andreturn();      mvcresult.getasyncresult();      restthumbnailmockmvc.perform(asyncdispatch(mvcresult))                         .anddo(print())                         .andexpect(status().isok())                         .andexpect(content().contenttype(mediatype.application_json))                         .andexpect(jsonpath("$.[*].id").value(hasitem(thumbnail.getid().longvalue())))                         .andexpect(jsonpath("$.[*].name").value(hasitem(default_name)))                         .andexpect(jsonpath("$.[*].filename").value(hasitem(default_file_name))); } 

the repository , stuff simple spring data jpa bean , whole configuration based on spring boot.

if query controller in normal way every thing works fine in test repository returns no results.

many on in advanced, can not find similar on web.

ok after bit trial , error figured out went wrong.

the problem is/was test method run in transaction , reason same transaction not accessed in callable of controller while test runs. after removing @transactional annotation test method every thing works fine.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -