Fixing return codes for user service v2
This commit is contained in:
parent
bbf073c7da
commit
fa2cce07a9
|
@ -220,6 +220,9 @@ public class DefaultUserService
|
||||||
public UserInfo createUser( User user )
|
public UserInfo createUser( User user )
|
||||||
throws RedbackServiceException
|
throws RedbackServiceException
|
||||||
{
|
{
|
||||||
|
if (user==null) {
|
||||||
|
throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_ID_EMPTY ), 422 );
|
||||||
|
}
|
||||||
UserInfo result;
|
UserInfo result;
|
||||||
if ( Arrays.binarySearch( INVALID_CREATE_USER_NAMES, user.getUserId( ) ) >= 0 )
|
if ( Arrays.binarySearch( INVALID_CREATE_USER_NAMES, user.getUserId( ) ) >= 0 )
|
||||||
{
|
{
|
||||||
|
@ -307,6 +310,9 @@ public class DefaultUserService
|
||||||
public void deleteUser( String userId )
|
public void deleteUser( String userId )
|
||||||
throws RedbackServiceException
|
throws RedbackServiceException
|
||||||
{
|
{
|
||||||
|
if (StringUtils.isEmpty( userId )) {
|
||||||
|
throw new RedbackServiceException( MessageKeys.ERR_USER_ID_EMPTY, 404 );
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -348,6 +354,9 @@ public class DefaultUserService
|
||||||
public UserInfo getUser( String userId )
|
public UserInfo getUser( String userId )
|
||||||
throws RedbackServiceException
|
throws RedbackServiceException
|
||||||
{
|
{
|
||||||
|
if (StringUtils.isEmpty( userId)) {
|
||||||
|
throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_ID_EMPTY ), 404 );
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( "guest".equals( userId ) )
|
if ( "guest".equals( userId ) )
|
||||||
|
@ -359,7 +368,7 @@ public class DefaultUserService
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
{
|
{
|
||||||
return null;
|
throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_NOT_FOUND ), 404 );
|
||||||
}
|
}
|
||||||
catch ( UserManagerException e )
|
catch ( UserManagerException e )
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.ForbiddenException;
|
import javax.ws.rs.ForbiddenException;
|
||||||
|
import javax.ws.rs.NotFoundException;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -564,7 +565,13 @@ public class UserServiceTest
|
||||||
{
|
{
|
||||||
getUserService( getAdminAuthzHeader( ) ).deleteUser( "toto" );
|
getUserService( getAdminAuthzHeader( ) ).deleteUser( "toto" );
|
||||||
getUserService( getAdminAuthzHeader( ) ).removeFromCache( "toto" );
|
getUserService( getAdminAuthzHeader( ) ).removeFromCache( "toto" );
|
||||||
assertNull( getUserService( getAdminAuthzHeader( ) ).getUser( "toto" ) );
|
try
|
||||||
|
{
|
||||||
|
getUserService( getAdminAuthzHeader( ) ).getUser( "toto" );
|
||||||
|
assertTrue( false, "404 should be thrown for non existing resource" );
|
||||||
|
} catch ( NotFoundException e ) {
|
||||||
|
assertEquals( 404, e.getResponse( ).getStatus( ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue