java


Spring REST Integration tests, entity is not deleted


I have a UserControllerTest which is testing my UserConstroller. There is a test:
#Test
public void shouldRemoveUser() throws Exception {
mockMvc.perform(put("/user/register?email=test5#gmail.com&password=aaa"))
.andExpect(status().isOk());
mockMvc.perform(get("/user?email=test5#gmail.com"))
.andExpect(status().isOk());
mockMvc.perform(delete("/user?email=test5#gmail.com"))
.andExpect(status().isOk());
mockMvc.perform(get("/user?email=test5#gmail.com"))
.andExpect(status().isNotFound());
}
And the implementation which I want to test:
#RequestMapping(value = "register")
public ResponseEntity<?> createUser(
#RequestParam(value = "email") String email,
#RequestParam(value = "password", defaultValue = "") String password) {
MyUser myUser = new [...]
userRepository.save(myUser );
return ResponseEntity.ok(myUser);
}
#RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<?> delete(#RequestParam(value = "email") String email) {
MyUser userByEmail = userRepository.findMyUserByEmail(email);
if (userByEmail == null) {
LOG.debug("Cannot delete user with id: {}", email);
throw new UserNotFoundException("Cannot find user with email: " + email);
}
userRepository.delete(userByEmail);
return ResponseEntity.ok().build();
}
Turns out that the method delete works perfectly fine when fired via Postman or any other Rest Client. However, in tests the result is as follows:
java.lang.AssertionError: Status
Expected :404
Actual :200
It seams like the user is somehow not deleted when the code runs in tests.
In test I used H2, but when I tried to test it manually via Postman I used PostgreSQL.

Related Links

Object translation into another object with the same data? Java
Where to add events to nodes?
How to intent activity use AlertDialog?
Cannot open activity from Fragment inside onSuccess
Spring MVC testing, JNDI
How to recieve data from libpd pd-for-android
Android - Error Manifest merger failed
android How to load sqlite data in Asyntask in android
JavaFX column/cell-value not updating
PMD rule “Use Proper Class Loader” explaination?
i was create two log files using RollingFileAppender in log4j.xml
How do I use a custom SSLContextFactory in a Restlet application running on Jetty?
why this code runs out of order
how do i use the information from a deep link url that opens an activity in android? [closed]
How to store a splitted string into an array?
JMeter: java.net.URISyntaxException: Malformed escape pair at index

Categories

HOME
ibm-bluemix
xamarin
clips
hive
wso2
debugging
proxy
mockito
pycharm
plone
react-virtualized
platform-builder
syntax
rsyslog
fingerprint
multiple-records
add
synchronization
kentor-authservices
windows-server-2012
ups
progressive-web-apps
jqwidget
text-rendering
openedx
viewport
ml
csrf-protection
php-openssl
restful-authentication
lcd
info.plist
fluentvalidation
socialengine
frame
binary-data
yadcf
catel
windows-dev-center
accelerate-framework
android-nestedscrollview
y86
picasso
bitbucket-pipelines
hot-module-replacement
abstract-class
temporary-files
hp-ux
g-code
jvm-languages
osx-mavericks
celery-task
return-value
dotnetzip
tactic
diagnostics
android-cursor
namecoin
spring-cache
minimization
angular-strap
static-ip-address
file-writing
fputcsv
sdf
photobucket
uid
srand
reactive-banana
teamcity-8.0
sdhc
libressl
tableau-online
sniffer
dundas
bridge.net
modalpopup
oxwall
pick
neolane
dir
jmapviewer
bitsharp
cisco-jtapi
dice
newtonscript
viewswitcher
hosts-file
appconkit
spring-portlet-mvc
gnustep
infobox
django-tagging
oncheckedchanged
imac
mysql-error-1005
web-application-design
modelstate
dbal
phonon
paul-graham

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