spring-async


Testing ASync method with JUnit in Spring MVC


I have a scenario where i need to test async method.
I have XML based configuration and is looks like below
<task:annotation-driven executor="myExecutor"
scheduler="myScheduler" />
<task:executor id="myExecutor" pool-size="5" />
<task:scheduler id="myScheduler" pool-size="10" />
Original Async method in controller as below
#Async
public Future<ResponseEntity<?>> saveData(#RequestParam("file") MultipartFile file) {
byte[] gzipContents = null;
try {
gzipContents = file.getBytes();
} catch (IOException ioEx) {
}
if (gzipContents != null) {
FileDTO fileDTO = new FileDTO(gzipContents);
boolean response = storingService.processData(fileDTO);
return new AsyncResult(new ResponseEntity<>(new ApiResponse<Boolean>(response, true), HttpStatus.OK));
}
return new AsyncResult(new ResponseEntity<>(new ApiResponse<Boolean>(false, true), HttpStatus.OK));
}
And my test case looks as below.
#RunWith(SpringJUnit4ClassRunner.class)
#Transactional
public class TestSave extends BaseIntegrationTest {
#Test
public void testTrackingDataSave() throws Exception {
// setup
MvcResult mvcResult = this.mockMvc
.perform(MockMvcRequestBuilders.fileUpload(API_TESTER_SAVETRACKINGDATA)
.file("file", readFileBytesFromClasspath("testdata/output_sample1.txt"))
.header("certificate", testerCertificate))
.andExpect(request().asyncStarted()).andReturn();
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(status().is(200));
}}
When u run this test i am getting exception as async started expected as true but false.
How do need to proceed to fix this problem. Am i missing something..?

Related Links

How to use spring #Async in dependent projects
Testing ASync method with JUnit in Spring MVC

Categories

HOME
phantom-dsl
cobalt
deep-learning
ng-idle
android-studio-2.2
mjml
case
swt
battery
obfuscation
seo
nested-if
maxscript
pearson-correlation
tvos
crystal-lang
octave
ibeacon-android
distribution
plist
3nf
scrolltop
screen-readers
internationalization
esoteric-languages
symfony-2.8
null-pointer
xmonad
solrcloud
exit
dapper-extensions
windows-server-2003
has-and-belongs-to-many
bringtofront
mql
testcomplete
alm
google-cast
anki
kudu
git-squash
catch-unit-test
linkedhashmap
instantiation
dynamic-jasper
carriage-return
reverse
google-earth-engine
health-monitoring
claims
xmldocument
uiimage
pom.xml
ovf
wcftestclient
corruption
er-diagram
css-transforms
java-websocket
stripe-connect
vulcanize
neon
macaulay2
windows-azure-queues
clipboard.js
jtwig
mediametadataretriever
bizagi
boost-serialization
atan2
themoviedb-api
morton-number
opserver
branch-and-bound
liquid-layout
omnifaces
packet-sniffers
iiop
genymotion-call
encryption-asymmetric
ignite-ui
alternate
ecslidingviewcontroller
scriptaculous
kogrid
scringo
web-farm
subproject
josql
lambdaj
azman
jsr286
jquery-address
google-ajax-api
http-daemon
sifr
murmurhash
perl5.12
linfu-dynamicproxy
appliance

Resources

Encrypt Message