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

How to control the timeout in Domino NotesFactory.createSessionWithIOR?
Select element in webpage using selenium
jaxrs Urifinfo not populating correct information with weblogic cluster
Java mail from virtual mail Id like node mailer
How to put JSONB thought Postgres database with JPA
Why can't I erase my Sprite
chronicle queue serialising throwables
How to serve legacy jsp pages alongside Spring MVC in spring boot?
Create and populate HashMap<Integer, ArrayList<object>>
How to set Layout with another class in Java?
How to load a sprite then display it on a JPanel?
Get Notification after receiving an email
How the counter works? / Very basic Java
How to include cucumber IT results in html surefire report runned with JUnit
Test Database Class in java
Printing the position of character in a String

Categories

HOME
log4j
homebrew
include
hashmap
getelementsbytagname
rubygems
cross-browser
opengl-es-2.0
upload
medical
awesome-wm
iggrid
vifm
modx-revolution
windows-phone-7
size
serverless-framework
windows-7-x64
lldb
swiftlint
ml
dcevm
java-7
shopware
publish
procdump
bluestacks
google-cloud-endpoints-v2
data-manipulation
siesta-swift
catel
wallpaper
normal-distribution
wpf-controls
multilingual
c11
uft-api
reportbuilder
ansible-playbook
g-code
google-closure
pebble-watch
drupal-6
snmptrapd
sqlbulkcopy
gnome-shell-extensions
messenger
ableton-live
deadbolt-2
fody
merge-conflict-resolution
plottable.js
clang-static-analyzer
angstrom-linux
moveit
sdf
php-internals
goose
iad
prerequisites
lib.web.mvc
retina
wordml
map-projections
composite
rdtsc
nsbutton
bitcoinj
phpthumb
viadeo
html5-notifications
commoncrypto
web2py-modules
listings
qt-faststart
ember-app-kit
cassini-dev
wsdl-2.0
specification-pattern
path-separator
funscript
tridion-worldserver
asyncfileupload
xtype
rfc1123
zend-translate
gallio
webkit.net
backcolor
defensive-programming
genealogy
wsdl.exe
.net-1.0

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App