java


Testing async controllers using MockMvc


I have a controller that returns a DeferredResult, it is a POST.
Controller:
#RequestMapping(value = "/{customerId}/cards", method = RequestMethod.POST)
#ResponseBody
public DeferredResult<CardSummaryQuery> createCard(
#PathVariable String customerId,
#RequestBody CustomerDto payload) {
DeferredResult<CardSummaryQuery> deferred = new DeferredResult<>();
Observable<CardSummaryQuery> observable =
cardService.registerCardObservable(customerId, payload);
observable.subscribe(deferred::setResult, deferred::setErrorResult);
return deferred;
}
I am trying to test it but receiving the following error: "java.lang.AssertionError: Content type not set"
MvcResult result = mockMvc
.perform(post("/customers/55e5d-4df4r-v4fgt/cards").content(payload)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(request().asyncStarted())
.andExpect(request().asyncResult("Deferred result")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(jsonPath("$.success").value(true));
What can I do to solve?

Related Links

How to manually create a class instance with Spring
rollback in Managed bean doesn't not ignore form validation
Why am I getting “Cannot find symbol” error when I already defined the statements in another.java file?
How to use function reference for Java 8?
Is a MessageBodyWriter used in constructing the WADL in ServiceMix / cxf?
How to display Map values in ListView?
Java: File name is not correct when downloading zip file in play
Spring default implementation of command design pattern
Android DrawerMenu selected item not showing properly in UI
Spring Autowire Without Setter Method
HackerRank Java 1D Array (Part 2)
NullPointerException error and could not solve [duplicate]
Why this inner class code compiles?
Efficiently adding huge amounts of data from CSV files into an SQLite DB in Java [duplicate]
How to mock several static classes by PowerMockito
Java date format convertion [duplicate]

Categories

HOME
compiler-construction
testing
multithreading
blogger
plot
appx
relayjs
electron
at-command
sharepoint-designer
packages
fancybox
ios-charts
directx
elasticsearch-hadoop
facebook-php-sdk
circuit
saxon
aurigma
samoa
karma-jasmine
swingx
kryo
csrf-protection
wkwebview
restful-authentication
autosys
emgucv
p-value
angular2-aot
numerical-methods
microsoft-sync-framework
jspm
azure-sql-database
qwerty
libraries
serverside-rendering
occlusion
sharefile
c11
mesos-chronos
preconditions
ruby-on-rails-3.1
grid.mvc
janrain
nomethoderror
turbogears
netcdf4
babel-core
auto-update
parentheses
youcompleteme
jquery-validate
blogengine.net
pearson
cudafy.net
spring-mongodb
vtigercrm
google-cdn
azure-sdk
infix-notation
azure-virtual-network
paypal-express
gridview-sorting
disque
qcustomplot
phpcas
lib.web.mvc
cartesian-product
t4mvc
citrus-pay
splash
device-orientation
geonetwork
client-side-templating
titanium-modules
gulp-less
comexception
dealloc
imdbpy
listings
jplaton
pvrtc
objective-c-2.0
online-compilation
tomcat-valve
rfc1123
servicehost
locate
gdlib
iphone-web-app
google-friend-connect
web-architecture
w3wp
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App