From 98d05506cef2d55a473721282a44ec1d33bdfc60 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Fri, 25 Dec 2020 17:56:09 +0100 Subject: [PATCH 01/32] FF-251 Added basic structure and exception + handler. --- .../business/FileSystemBusinessService.java | 4 ++++ ...FileSystemItemCouldNotBeDeletedAdvise.java | 24 +++++++++++++++++++ ...eSystemItemCouldNotBeDeletedException.java | 12 ++++++++++ .../rest/FileSystemRestService.java | 10 ++++++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedAdvise.java create mode 100644 src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java index bda488f5..770ec9a8 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java @@ -131,6 +131,10 @@ public boolean userIsAllowedToSeeFileSystemEntity(FileSystemEntity fileSystemEnt return false; } + public void deleteFileSystemItemById(long fsItemId, User authenticatedUser) { + + } + public FileSystemItem createDTO(FileSystemEntity fileSystemEntity, User authenticatedUser, String basePath) { User ownerOfFileSystemItem = userBusinessService.getUserById(fileSystemEntity.getCreatedByUserId()); diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedAdvise.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedAdvise.java new file mode 100644 index 00000000..2fbfc67f --- /dev/null +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedAdvise.java @@ -0,0 +1,24 @@ +package de.filefighter.rest.domain.filesystem.exceptions; + +import de.filefighter.rest.rest.ServerResponse; +import lombok.extern.log4j.Log4j2; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Log4j2 +@ControllerAdvice +public class FileSystemItemCouldNotBeDeletedAdvise { + + @ResponseBody + @ExceptionHandler(FileSystemItemCouldNotBeDeletedException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + ResponseEntity fileSystemContentsNotAccessibleAdvise(FileSystemItemCouldNotBeDeletedException ex) { + log.warn(ex.getMessage()); + return new ResponseEntity<>(new ServerResponse(HttpStatus.BAD_REQUEST, ex.getMessage()), HttpStatus.BAD_REQUEST); + } + +} \ No newline at end of file diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java new file mode 100644 index 00000000..8e6a4bfd --- /dev/null +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java @@ -0,0 +1,12 @@ +package de.filefighter.rest.domain.filesystem.exceptions; + +public class FileSystemItemCouldNotBeDeletedException extends RuntimeException { + + public FileSystemItemCouldNotBeDeletedException() { + super("FileSystemEntity could not be deleted."); + } + + public FileSystemItemCouldNotBeDeletedException(long fileSystemId) { + super("FileSystemEntity with the fileSystemId " + fileSystemId + " could not be deleted."); + } +} diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java b/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java index 10f32569..4557fea3 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java @@ -70,7 +70,13 @@ public ResponseEntity updatedFileSystemItemWithIdAndAccessToken( } @Override - public ResponseEntity deleteFileSystemItemWithIdAndAccessToken(long fsItemId, String accessToken) { - return null; + public ResponseEntity deleteFileSystemItemWithIdAndAccessToken(long fsItemId, String accessTokenValue) { + String cleanHeader = inputSanitizerService.sanitizeRequestHeader(AUTHORIZATION_BEARER_PREFIX, accessTokenValue); + String cleanValue = inputSanitizerService.sanitizeTokenValue(cleanHeader); + AccessToken accessToken = accessTokenBusinessService.findAccessTokenByValue(cleanValue); + User authenticatedUser = userAuthorizationService.authenticateUserWithAccessToken(accessToken); + + fileSystemBusinessService.deleteFileSystemItemById(fsItemId, authenticatedUser); + return new ResponseEntity<>(new ServerResponse(HttpStatus.NO_CONTENT, "FileSystemItem was deleted."), HttpStatus.NO_CONTENT); } } From 7f03f3ff33200e7415a0ec11ae46ed4c74f7fc91 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Fri, 25 Dec 2020 18:20:29 +0100 Subject: [PATCH 02/32] Cleanup. Reworked custom Exceptions. --- .../exceptions/DataBaseExceptionAdvise.java | 2 +- .../exceptions/FileFighterDataException.java | 17 ++++++++++++++ .../exceptions/FileFighterException.java | 5 ++++ .../InputSanitizerService.java | 3 +-- ...uestDidntMeetFormalRequirementsAdvise.java | 2 +- ...tDidntMeetFormalRequirementsException.java | 19 +++++++++++++++ .../business/FileSystemBusinessService.java | 6 ++--- ...eSystemContentsNotAccessibleException.java | 16 ++++++++++--- ...eSystemItemCouldNotBeDeletedException.java | 19 ++++++++++++--- .../FileSystemItemNotFoundException.java | 15 +++++++++--- .../rest/FileSystemRestService.java | 2 +- .../business/AccessTokenBusinessService.java | 2 +- .../token/business/AccessTokenDTOService.java | 2 +- .../AccessTokenNotFoundException.java | 15 +++++++++--- .../business/UserAuthorizationService.java | 4 ++-- .../user/business/UserBusinessService.java | 4 ++-- .../UserNotAuthenticatedException.java | 20 ++++++++++++---- .../exceptions/UserNotFoundException.java | 23 +++++++++++++------ .../UserNotRegisteredException.java | 15 +++++++++--- .../exceptions/UserNotUpdatedException.java | 16 ++++++++++--- .../domain/user/rest/UserRestService.java | 2 +- .../exceptions/FileFighterDataException.java | 9 -------- ...tDidntMeetFormalRequirementsException.java | 12 ---------- .../common/InputSanitizerServiceUnitTest.java | 3 ++- .../FileSystemBusinessServiceUnitTest.java | 2 +- .../AccessTokenBusinessServiceUnitTest.java | 2 +- .../UserAuthorizationServiceUnitTest.java | 2 +- 27 files changed, 169 insertions(+), 70 deletions(-) rename src/main/java/de/filefighter/rest/{rest => domain/common}/exceptions/DataBaseExceptionAdvise.java (96%) create mode 100644 src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java create mode 100644 src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java rename src/main/java/de/filefighter/rest/domain/common/{ => exceptions}/InputSanitizerService.java (91%) rename src/main/java/de/filefighter/rest/{rest => domain/common}/exceptions/RequestDidntMeetFormalRequirementsAdvise.java (94%) create mode 100644 src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java delete mode 100644 src/main/java/de/filefighter/rest/rest/exceptions/FileFighterDataException.java delete mode 100644 src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsException.java diff --git a/src/main/java/de/filefighter/rest/rest/exceptions/DataBaseExceptionAdvise.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/DataBaseExceptionAdvise.java similarity index 96% rename from src/main/java/de/filefighter/rest/rest/exceptions/DataBaseExceptionAdvise.java rename to src/main/java/de/filefighter/rest/domain/common/exceptions/DataBaseExceptionAdvise.java index 74fb256a..e2c70d5a 100644 --- a/src/main/java/de/filefighter/rest/rest/exceptions/DataBaseExceptionAdvise.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/DataBaseExceptionAdvise.java @@ -1,4 +1,4 @@ -package de.filefighter.rest.rest.exceptions; +package de.filefighter.rest.domain.common.exceptions; import de.filefighter.rest.domain.health.business.SystemHealthBusinessService; import de.filefighter.rest.domain.health.data.SystemHealth; diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java new file mode 100644 index 00000000..aaaac4f0 --- /dev/null +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java @@ -0,0 +1,17 @@ +package de.filefighter.rest.domain.common.exceptions; + +import org.springframework.core.NestedRuntimeException; + +public class FileFighterDataException extends NestedRuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "Internal Error occurred."; + + public FileFighterDataException(String msg) { + super(ERROR_MESSAGE_PREFIX + " " + msg); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; + } +} diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java new file mode 100644 index 00000000..a4d824c6 --- /dev/null +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java @@ -0,0 +1,5 @@ +package de.filefighter.rest.domain.common.exceptions; + +public interface FileFighterException { + String getErrorMessagePrefix(); +} diff --git a/src/main/java/de/filefighter/rest/domain/common/InputSanitizerService.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/InputSanitizerService.java similarity index 91% rename from src/main/java/de/filefighter/rest/domain/common/InputSanitizerService.java rename to src/main/java/de/filefighter/rest/domain/common/exceptions/InputSanitizerService.java index db0e1bf7..9218dcf3 100644 --- a/src/main/java/de/filefighter/rest/domain/common/InputSanitizerService.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/InputSanitizerService.java @@ -1,6 +1,5 @@ -package de.filefighter.rest.domain.common; +package de.filefighter.rest.domain.common.exceptions; -import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException; import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsAdvise.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsAdvise.java similarity index 94% rename from src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsAdvise.java rename to src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsAdvise.java index d5ec6199..c7351495 100644 --- a/src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsAdvise.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsAdvise.java @@ -1,4 +1,4 @@ -package de.filefighter.rest.rest.exceptions; +package de.filefighter.rest.domain.common.exceptions; import de.filefighter.rest.rest.ServerResponse; import lombok.extern.log4j.Log4j2; diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java new file mode 100644 index 00000000..a8a1a60a --- /dev/null +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java @@ -0,0 +1,19 @@ +package de.filefighter.rest.domain.common.exceptions; + +public class RequestDidntMeetFormalRequirementsException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "Request didnt meet formal requirements."; + + public RequestDidntMeetFormalRequirementsException() { + super(ERROR_MESSAGE_PREFIX); + } + + public RequestDidntMeetFormalRequirementsException(String reason) { + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; + } +} diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java index 770ec9a8..9a3c4436 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java @@ -1,6 +1,7 @@ package de.filefighter.rest.domain.filesystem.business; -import de.filefighter.rest.domain.common.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.FileFighterDataException; +import de.filefighter.rest.domain.common.exceptions.InputSanitizerService; import de.filefighter.rest.domain.filesystem.data.dto.FileSystemItem; import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemEntity; import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemRepository; @@ -12,7 +13,6 @@ import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.data.persistence.UserEntity; import de.filefighter.rest.domain.user.group.Groups; -import de.filefighter.rest.rest.exceptions.FileFighterDataException; import lombok.extern.log4j.Log4j2; import org.springframework.stereotype.Service; @@ -132,7 +132,7 @@ public boolean userIsAllowedToSeeFileSystemEntity(FileSystemEntity fileSystemEnt } public void deleteFileSystemItemById(long fsItemId, User authenticatedUser) { - + //WIP } public FileSystemItem createDTO(FileSystemEntity fileSystemEntity, User authenticatedUser, String basePath) { diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java index a7d17554..7c096dc6 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java @@ -1,12 +1,22 @@ package de.filefighter.rest.domain.filesystem.exceptions; -public class FileSystemContentsNotAccessibleException extends RuntimeException { +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class FileSystemContentsNotAccessibleException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "Folder does not exist, or you are not allowed to see the folder."; + public FileSystemContentsNotAccessibleException() { - super("Folder does not exist, or you are not allowed to see the folder."); + super(ERROR_MESSAGE_PREFIX); } public FileSystemContentsNotAccessibleException(String reason) { - super("Folder contents could not be displayed. "+reason); + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java index 8e6a4bfd..aef7b1b2 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java @@ -1,12 +1,25 @@ package de.filefighter.rest.domain.filesystem.exceptions; -public class FileSystemItemCouldNotBeDeletedException extends RuntimeException { +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class FileSystemItemCouldNotBeDeletedException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "FileSystemEntity could not be deleted."; public FileSystemItemCouldNotBeDeletedException() { - super("FileSystemEntity could not be deleted."); + super(ERROR_MESSAGE_PREFIX); } public FileSystemItemCouldNotBeDeletedException(long fileSystemId) { - super("FileSystemEntity with the fileSystemId " + fileSystemId + " could not be deleted."); + super(ERROR_MESSAGE_PREFIX+" FileSystemId was "+fileSystemId); + } + + public FileSystemItemCouldNotBeDeletedException(String reason) { + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java index ac36521d..00b9bb7f 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java @@ -1,12 +1,21 @@ package de.filefighter.rest.domain.filesystem.exceptions; -public class FileSystemItemNotFoundException extends RuntimeException { +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class FileSystemItemNotFoundException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "FileSystemItem could not be found or you are not allowed to view it."; public FileSystemItemNotFoundException() { - super("FileSystemItem could not be found or you are not allowed to view it."); + super(ERROR_MESSAGE_PREFIX); } public FileSystemItemNotFoundException(long fsItemId) { - super("FileSystemItem with id " + fsItemId + " could not be found or you are not allowed to view it."); + super(ERROR_MESSAGE_PREFIX + " FileSystemId was " + fsItemId); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java b/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java index 4557fea3..d686a0be 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java @@ -1,6 +1,6 @@ package de.filefighter.rest.domain.filesystem.rest; -import de.filefighter.rest.domain.common.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.InputSanitizerService; import de.filefighter.rest.domain.filesystem.business.FileSystemBusinessService; import de.filefighter.rest.domain.filesystem.data.dto.FileSystemItem; import de.filefighter.rest.domain.filesystem.data.dto.FileSystemItemUpdate; diff --git a/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessService.java b/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessService.java index 73e1bfd1..dec599ad 100644 --- a/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessService.java +++ b/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessService.java @@ -1,11 +1,11 @@ package de.filefighter.rest.domain.token.business; +import de.filefighter.rest.domain.common.exceptions.FileFighterDataException; import de.filefighter.rest.domain.token.data.dto.AccessToken; import de.filefighter.rest.domain.token.data.persistence.AccessTokenEntity; import de.filefighter.rest.domain.token.data.persistence.AccessTokenRepository; import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.exceptions.UserNotAuthenticatedException; -import de.filefighter.rest.rest.exceptions.FileFighterDataException; import lombok.extern.log4j.Log4j2; import org.springframework.stereotype.Service; diff --git a/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenDTOService.java b/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenDTOService.java index 12f7ba23..97846961 100644 --- a/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenDTOService.java +++ b/src/main/java/de/filefighter/rest/domain/token/business/AccessTokenDTOService.java @@ -30,7 +30,7 @@ public AccessToken createDto(AccessTokenEntity entity) { public AccessTokenEntity findEntity(AccessToken dto) { AccessTokenEntity accessTokenEntity = accessTokenRepository.findByUserIdAndValue(dto.getUserId(), dto.getTokenValue()); if (null == accessTokenEntity) - throw new AccessTokenNotFoundException("AccessTokenEntity does not exist for AccessToken with userId "+ dto.getUserId()+"."); + throw new AccessTokenNotFoundException(dto.getUserId()); return accessTokenEntity; } diff --git a/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java b/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java index adecc922..05f11d55 100644 --- a/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java @@ -1,8 +1,17 @@ package de.filefighter.rest.domain.token.exceptions; -public class AccessTokenNotFoundException extends RuntimeException { +import de.filefighter.rest.domain.common.exceptions.FileFighterException; - public AccessTokenNotFoundException(String reason) { - super(reason); +public class AccessTokenNotFoundException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "AccessToken could not be found."; + + public AccessTokenNotFoundException(long userId) { + super(ERROR_MESSAGE_PREFIX + " The userId was " + userId); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/business/UserAuthorizationService.java b/src/main/java/de/filefighter/rest/domain/user/business/UserAuthorizationService.java index 75580651..b0dacabc 100644 --- a/src/main/java/de/filefighter/rest/domain/user/business/UserAuthorizationService.java +++ b/src/main/java/de/filefighter/rest/domain/user/business/UserAuthorizationService.java @@ -1,13 +1,13 @@ package de.filefighter.rest.domain.user.business; -import de.filefighter.rest.domain.common.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.RequestDidntMeetFormalRequirementsException; import de.filefighter.rest.domain.token.data.dto.AccessToken; import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.data.persistence.UserEntity; import de.filefighter.rest.domain.user.data.persistence.UserRepository; import de.filefighter.rest.domain.user.exceptions.UserNotAuthenticatedException; import de.filefighter.rest.domain.user.group.Groups; -import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException; import lombok.extern.log4j.Log4j2; import org.springframework.stereotype.Service; diff --git a/src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java b/src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java index 73155222..f1b363c0 100644 --- a/src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java +++ b/src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.regex.Pattern; -import static de.filefighter.rest.domain.common.InputSanitizerService.stringIsValid; +import static de.filefighter.rest.domain.common.exceptions.InputSanitizerService.stringIsValid; @Service public class UserBusinessService { @@ -77,7 +77,7 @@ public RefreshToken getRefreshTokenForUser(User user) { public User findUserByUsername(String username) { UserEntity entity = getUserWithUsername(username); if (null == entity) - throw new UserNotFoundException("User with username '" + username + "' not found."); + throw new UserNotFoundException(username); return userDtoService.createDto(entity); } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java index 39bbc12e..e08b8e62 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java @@ -1,11 +1,21 @@ package de.filefighter.rest.domain.user.exceptions; -public class UserNotAuthenticatedException extends RuntimeException{ - public UserNotAuthenticatedException(String reason){ - super("User could not be authenticated. "+reason); +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class UserNotAuthenticatedException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "User could not be authenticated."; + + public UserNotAuthenticatedException(String reason) { + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + public UserNotAuthenticatedException(long userId) { + super(ERROR_MESSAGE_PREFIX+" UserId was "+userId); } - public UserNotAuthenticatedException(long id){ - super("User with the id "+id+" could not be authenticated."); + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java index f1d187af..b05f1c60 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java @@ -1,16 +1,25 @@ package de.filefighter.rest.domain.user.exceptions; -public class UserNotFoundException extends RuntimeException { +import de.filefighter.rest.domain.common.exceptions.FileFighterException; - public UserNotFoundException(){ - super("User not found."); +public class UserNotFoundException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "User not found."; + + public UserNotFoundException() { + super(ERROR_MESSAGE_PREFIX); + } + + public UserNotFoundException(long userId) { + super(ERROR_MESSAGE_PREFIX + " UserId was " + userId); } - public UserNotFoundException(long id) { - super("Could not find user with userId " + id+"."); + public UserNotFoundException(String username) { + super(ERROR_MESSAGE_PREFIX + " Username was " + username); } - public UserNotFoundException(String message) { - super(message); + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java index d43677a7..8fe8c1c1 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java @@ -1,12 +1,21 @@ package de.filefighter.rest.domain.user.exceptions; -public class UserNotRegisteredException extends RuntimeException{ +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class UserNotRegisteredException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "User could not be registered."; public UserNotRegisteredException() { - super("User could not be registered."); + super(ERROR_MESSAGE_PREFIX); } public UserNotRegisteredException(String reason) { - super("User could not be registered. "+reason); + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java index 0c29e4c8..a894c94f 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java @@ -1,11 +1,21 @@ package de.filefighter.rest.domain.user.exceptions; -public class UserNotUpdatedException extends RuntimeException{ +import de.filefighter.rest.domain.common.exceptions.FileFighterException; + +public class UserNotUpdatedException extends RuntimeException implements FileFighterException { + + private static final String ERROR_MESSAGE_PREFIX = "User could not get updated"; + public UserNotUpdatedException() { - super("User could not get updated"); + super(ERROR_MESSAGE_PREFIX); } public UserNotUpdatedException(String reason) { - super("User could not get updated. "+reason); + super(ERROR_MESSAGE_PREFIX + " " + reason); + } + + @Override + public String getErrorMessagePrefix() { + return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/rest/UserRestService.java b/src/main/java/de/filefighter/rest/domain/user/rest/UserRestService.java index 50dde960..343f2e6e 100644 --- a/src/main/java/de/filefighter/rest/domain/user/rest/UserRestService.java +++ b/src/main/java/de/filefighter/rest/domain/user/rest/UserRestService.java @@ -1,6 +1,6 @@ package de.filefighter.rest.domain.user.rest; -import de.filefighter.rest.domain.common.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.InputSanitizerService; import de.filefighter.rest.domain.filesystem.business.FileSystemBusinessService; import de.filefighter.rest.domain.token.business.AccessTokenBusinessService; import de.filefighter.rest.domain.token.data.dto.AccessToken; diff --git a/src/main/java/de/filefighter/rest/rest/exceptions/FileFighterDataException.java b/src/main/java/de/filefighter/rest/rest/exceptions/FileFighterDataException.java deleted file mode 100644 index c0169acd..00000000 --- a/src/main/java/de/filefighter/rest/rest/exceptions/FileFighterDataException.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.filefighter.rest.rest.exceptions; - -import org.springframework.core.NestedRuntimeException; - -public class FileFighterDataException extends NestedRuntimeException { - public FileFighterDataException(String msg) { - super("Internal Error occurred. " + msg); - } -} diff --git a/src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsException.java b/src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsException.java deleted file mode 100644 index ae38e01c..00000000 --- a/src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsException.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.filefighter.rest.rest.exceptions; - -public class RequestDidntMeetFormalRequirementsException extends RuntimeException{ - - public RequestDidntMeetFormalRequirementsException() { - super("Request didnt meet formal requirements."); - } - - public RequestDidntMeetFormalRequirementsException(String message) { - super("Request didnt meet formal requirements. "+message); - } -} diff --git a/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java index af9ab1d2..73058fbd 100644 --- a/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java @@ -1,6 +1,7 @@ package de.filefighter.rest.domain.common; -import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException; +import de.filefighter.rest.domain.common.exceptions.InputSanitizerService; +import de.filefighter.rest.domain.common.exceptions.RequestDidntMeetFormalRequirementsException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java index cf290ed6..e330ad11 100644 --- a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java @@ -1,5 +1,6 @@ package de.filefighter.rest.domain.filesystem.business; +import de.filefighter.rest.domain.common.exceptions.FileFighterDataException; import de.filefighter.rest.domain.filesystem.data.dto.FileSystemItem; import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemEntity; import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemRepository; @@ -10,7 +11,6 @@ import de.filefighter.rest.domain.user.business.UserBusinessService; import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.group.Groups; -import de.filefighter.rest.rest.exceptions.FileFighterDataException; import org.junit.jupiter.api.Test; import java.util.ArrayList; diff --git a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java index 1086bc3e..f1fd9916 100644 --- a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java @@ -1,11 +1,11 @@ package de.filefighter.rest.domain.token.business; +import de.filefighter.rest.domain.common.exceptions.FileFighterDataException; import de.filefighter.rest.domain.token.data.dto.AccessToken; import de.filefighter.rest.domain.token.data.persistence.AccessTokenEntity; import de.filefighter.rest.domain.token.data.persistence.AccessTokenRepository; import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.exceptions.UserNotAuthenticatedException; -import de.filefighter.rest.rest.exceptions.FileFighterDataException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java index 39ff9032..2215b6b7 100644 --- a/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java @@ -1,12 +1,12 @@ package de.filefighter.rest.domain.user.business; +import de.filefighter.rest.domain.common.exceptions.RequestDidntMeetFormalRequirementsException; import de.filefighter.rest.domain.token.data.dto.AccessToken; import de.filefighter.rest.domain.user.data.dto.User; import de.filefighter.rest.domain.user.data.persistence.UserEntity; import de.filefighter.rest.domain.user.data.persistence.UserRepository; import de.filefighter.rest.domain.user.exceptions.UserNotAuthenticatedException; import de.filefighter.rest.domain.user.group.Groups; -import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException; import org.junit.jupiter.api.Test; import static de.filefighter.rest.configuration.RestConfiguration.AUTHORIZATION_BEARER_PREFIX; From 8603fdf99cb0fcffb04d60d6266ea87cefb47961 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Fri, 25 Dec 2020 18:50:09 +0100 Subject: [PATCH 03/32] Cleanup. Implemented Change in UnitTests. --- .../exceptions/FileFighterDataException.java | 3 +- .../exceptions/FileFighterException.java | 4 +- ...tDidntMeetFormalRequirementsException.java | 3 +- ...eSystemContentsNotAccessibleException.java | 3 +- ...eSystemItemCouldNotBeDeletedException.java | 3 +- .../FileSystemItemNotFoundException.java | 3 +- .../AccessTokenNotFoundException.java | 5 +- .../UserNotAuthenticatedException.java | 3 +- .../exceptions/UserNotFoundException.java | 3 +- .../UserNotRegisteredException.java | 3 +- .../exceptions/UserNotUpdatedException.java | 3 +- .../domain/user/group/GroupRepository.java | 2 +- .../common/InputSanitizerServiceUnitTest.java | 16 +++--- .../FileSystemBusinessServiceUnitTest.java | 18 +++---- .../AccessTokenBusinessServiceUnitTest.java | 6 +-- .../AccessTokenDtoServiceUnitTest.java | 2 +- .../UserAuthorizationServiceUnitTest.java | 14 +++--- .../business/UserBusinessServiceUnitTest.java | 50 +++++++++---------- .../user/business/UserDtoServiceUnitTest.java | 2 +- .../user/group/GroupRepositoryUnitTest.java | 2 +- 20 files changed, 70 insertions(+), 78 deletions(-) diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java index aaaac4f0..75af5079 100644 --- a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterDataException.java @@ -10,8 +10,7 @@ public FileFighterDataException(String msg) { super(ERROR_MESSAGE_PREFIX + " " + msg); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java index a4d824c6..c85b2d15 100644 --- a/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/FileFighterException.java @@ -1,5 +1,7 @@ package de.filefighter.rest.domain.common.exceptions; public interface FileFighterException { - String getErrorMessagePrefix(); + static String getErrorMessagePrefix() { + throw new IllegalArgumentException("Custom exception should overwrite this message."); + } } diff --git a/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java index a8a1a60a..106f0afd 100644 --- a/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java +++ b/src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsException.java @@ -12,8 +12,7 @@ public RequestDidntMeetFormalRequirementsException(String reason) { super(ERROR_MESSAGE_PREFIX + " " + reason); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java index 7c096dc6..77b27701 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemContentsNotAccessibleException.java @@ -15,8 +15,7 @@ public FileSystemContentsNotAccessibleException(String reason) { super(ERROR_MESSAGE_PREFIX + " " + reason); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java index aef7b1b2..175b5f30 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemCouldNotBeDeletedException.java @@ -18,8 +18,7 @@ public FileSystemItemCouldNotBeDeletedException(String reason) { super(ERROR_MESSAGE_PREFIX + " " + reason); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java index 00b9bb7f..ef9d2393 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/exceptions/FileSystemItemNotFoundException.java @@ -14,8 +14,7 @@ public FileSystemItemNotFoundException(long fsItemId) { super(ERROR_MESSAGE_PREFIX + " FileSystemId was " + fsItemId); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java b/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java index 05f11d55..c9685d33 100644 --- a/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/token/exceptions/AccessTokenNotFoundException.java @@ -7,11 +7,10 @@ public class AccessTokenNotFoundException extends RuntimeException implements Fi private static final String ERROR_MESSAGE_PREFIX = "AccessToken could not be found."; public AccessTokenNotFoundException(long userId) { - super(ERROR_MESSAGE_PREFIX + " The userId was " + userId); + super(ERROR_MESSAGE_PREFIX + " UserId was " + userId); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java index e08b8e62..21d351a5 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotAuthenticatedException.java @@ -14,8 +14,7 @@ public UserNotAuthenticatedException(long userId) { super(ERROR_MESSAGE_PREFIX+" UserId was "+userId); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java index b05f1c60..407734a4 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotFoundException.java @@ -18,8 +18,7 @@ public UserNotFoundException(String username) { super(ERROR_MESSAGE_PREFIX + " Username was " + username); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java index 8fe8c1c1..ef19061f 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotRegisteredException.java @@ -14,8 +14,7 @@ public UserNotRegisteredException(String reason) { super(ERROR_MESSAGE_PREFIX + " " + reason); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java index a894c94f..5d2b51d5 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java @@ -14,8 +14,7 @@ public UserNotUpdatedException(String reason) { super(ERROR_MESSAGE_PREFIX + " " + reason); } - @Override - public String getErrorMessagePrefix() { + public static String getErrorMessagePrefix() { return ERROR_MESSAGE_PREFIX; } } diff --git a/src/main/java/de/filefighter/rest/domain/user/group/GroupRepository.java b/src/main/java/de/filefighter/rest/domain/user/group/GroupRepository.java index f5a6a340..c6514e71 100644 --- a/src/main/java/de/filefighter/rest/domain/user/group/GroupRepository.java +++ b/src/main/java/de/filefighter/rest/domain/user/group/GroupRepository.java @@ -12,7 +12,7 @@ public Groups getGroupById(long id) { return group; } } - throw new IllegalArgumentException("id "+id+" doesnt belong to a group."); + throw new IllegalArgumentException("GroupId "+id+" doesnt belong to a group."); } public Groups[] getGroupsByIds(long... ids){ diff --git a/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java index 73058fbd..4e7cb15f 100644 --- a/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/common/InputSanitizerServiceUnitTest.java @@ -26,11 +26,11 @@ void sanitizeStringThrows() { RequestDidntMeetFormalRequirementsException ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> InputSanitizerService.sanitizeString(string0)); - assertEquals("Request didnt meet formal requirements. String was empty.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" String was empty.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> InputSanitizerService.sanitizeString(string1)); - assertEquals("Request didnt meet formal requirements. String was empty.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" String was empty.", ex.getMessage()); } @Test @@ -54,19 +54,19 @@ void sanitizeRequestHeaderThrows() { RequestDidntMeetFormalRequirementsException ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeRequestHeader(header, string0)); - assertEquals("Request didnt meet formal requirements. Header does not contain a valid String.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" Header does not contain a valid String.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeRequestHeader(header, string1)); - assertEquals("Request didnt meet formal requirements. Header does not contain a valid String.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" Header does not contain a valid String.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeRequestHeader(header, string2)); - assertEquals("Request didnt meet formal requirements. Header does not contain '" + header + "', or format is invalid.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" Header does not contain '" + header + "', or format is invalid.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeRequestHeader(header, string3)); - assertEquals("Request didnt meet formal requirements. Header does not contain '" + header + "', or format is invalid.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" Header does not contain '" + header + "', or format is invalid.", ex.getMessage()); } @@ -88,11 +88,11 @@ void sanitizeTokenThrows() { RequestDidntMeetFormalRequirementsException ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeTokenValue(string0)); - assertEquals("Request didnt meet formal requirements. String was empty.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" String was empty.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> inputSanitizerService.sanitizeTokenValue(string1)); - assertEquals("Request didnt meet formal requirements. String was empty.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix()+" String was empty.", ex.getMessage()); } diff --git a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java index e330ad11..8be8ef5a 100644 --- a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java @@ -37,21 +37,21 @@ void getFolderContentsByPathThrows() { FileSystemContentsNotAccessibleException ex = assertThrows(FileSystemContentsNotAccessibleException.class, () -> fileSystemBusinessService.getFolderContentsByPath(notValid, dummyUser)); - assertEquals("Folder contents could not be displayed. Path was not valid.", ex.getMessage()); + assertEquals(FileSystemContentsNotAccessibleException.getErrorMessagePrefix() + " Path was not valid.", ex.getMessage()); ex = assertThrows(FileSystemContentsNotAccessibleException.class, () -> fileSystemBusinessService.getFolderContentsByPath(wrongFormat, dummyUser)); - assertEquals("Folder contents could not be displayed. Path was in wrong format.", ex.getMessage()); + assertEquals(FileSystemContentsNotAccessibleException.getErrorMessagePrefix() + " Path was in wrong format.", ex.getMessage()); ex = assertThrows(FileSystemContentsNotAccessibleException.class, () -> fileSystemBusinessService.getFolderContentsByPath(wrongFormat1, dummyUser)); - assertEquals("Folder contents could not be displayed. Path was in wrong format. Use a leading backslash.", ex.getMessage()); + assertEquals(FileSystemContentsNotAccessibleException.getErrorMessagePrefix() + " Path was in wrong format. Use a leading backslash.", ex.getMessage()); when(fileSystemRepositoryMock.findByPath(validPath)).thenReturn(null); ex = assertThrows(FileSystemContentsNotAccessibleException.class, () -> fileSystemBusinessService.getFolderContentsByPath(validPath, dummyUser)); - assertEquals("Folder does not exist, or you are not allowed to see the folder.", ex.getMessage()); + assertEquals(FileSystemContentsNotAccessibleException.getErrorMessagePrefix(), ex.getMessage()); ArrayList fileSystemEntityArrayList = new ArrayList<>(); fileSystemEntityArrayList.add(FileSystemEntity.builder().isFile(true).build()); @@ -62,7 +62,7 @@ void getFolderContentsByPathThrows() { ex = assertThrows(FileSystemContentsNotAccessibleException.class, () -> fileSystemBusinessService.getFolderContentsByPath(validPath, dummyUser)); - assertEquals("Folder does not exist, or you are not allowed to see the folder.", ex.getMessage()); + assertEquals(FileSystemContentsNotAccessibleException.getErrorMessagePrefix(), ex.getMessage()); } @Test @@ -97,7 +97,7 @@ void getFolderContentsOfEntityThrows() { FileFighterDataException ex = assertThrows(FileFighterDataException.class, () -> fileSystemBusinessService.getFolderContentsOfEntities(arrayList, authenticatedUser, "/")); - assertEquals("Internal Error occurred. FolderContents expected fileSystemItem with id " + fileSystemId + " but was empty.", ex.getMessage()); + assertEquals(FileFighterDataException.getErrorMessagePrefix() + " FolderContents expected fileSystemItem with id " + fileSystemId + " but was empty.", ex.getMessage()); } @Test @@ -128,12 +128,12 @@ void getFileSystemItemInfoThrows() { when(fileSystemRepositoryMock.findByFileSystemId(id)).thenReturn(null); FileSystemItemNotFoundException ex = assertThrows(FileSystemItemNotFoundException.class, () -> fileSystemBusinessService.getFileSystemItemInfo(id, dummyUser)); - assertEquals("FileSystemItem with id " + id + " could not be found or you are not allowed to view it.", ex.getMessage()); + assertEquals(FileSystemItemNotFoundException.getErrorMessagePrefix() + " FileSystemId was " + id, ex.getMessage()); when(fileSystemRepositoryMock.findByFileSystemId(id)).thenReturn(FileSystemEntity.builder().build()); ex = assertThrows(FileSystemItemNotFoundException.class, () -> fileSystemBusinessService.getFileSystemItemInfo(id, dummyUser)); - assertEquals("FileSystemItem with id " + id + " could not be found or you are not allowed to view it.", ex.getMessage()); + assertEquals(FileSystemItemNotFoundException.getErrorMessagePrefix() + " FileSystemId was " + id, ex.getMessage()); } @Test @@ -242,7 +242,7 @@ void createDTOWorks() { void getTotalFileSizeThrows() { when(fileSystemRepositoryMock.findByPath("/")).thenReturn(null); FileFighterDataException ex = assertThrows(FileFighterDataException.class, fileSystemBusinessService::getTotalFileSize); - assertEquals("Internal Error occurred. Couldn't find any Home directories!", ex.getMessage()); + assertEquals(FileFighterDataException.getErrorMessagePrefix() + " Couldn't find any Home directories!", ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java index f1fd9916..cd496223 100644 --- a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenBusinessServiceUnitTest.java @@ -97,7 +97,7 @@ void getValidAccessTokenForUserWhenTokenDeletionFails() { FileFighterDataException ex = assertThrows(FileFighterDataException.class, () -> accessTokenBusinessService.getValidAccessTokenForUser(dummyUser)); - assertEquals("Internal Error occurred. AccessToken for userId " + dummyId + " could not be deleted.", ex.getMessage()); + assertEquals(FileFighterDataException.getErrorMessagePrefix() + " AccessToken for userId " + dummyId + " could not be deleted.", ex.getMessage()); } @Test @@ -110,7 +110,7 @@ void findAccessTokenByValueAndUserIdWithTokenNotFound() { UserNotAuthenticatedException ex = assertThrows(UserNotAuthenticatedException.class, () -> accessTokenBusinessService.findAccessTokenByValueAndUserId(tokenValue, userId) ); - assertEquals("User with the id " + userId + " could not be authenticated.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix() + " UserId was " + userId, ex.getMessage()); } @Test @@ -137,7 +137,7 @@ void findAccessTokenByValueThrowsException() { UserNotAuthenticatedException ex = assertThrows(UserNotAuthenticatedException.class, () -> accessTokenBusinessService.findAccessTokenByValue(validFormat) ); - assertEquals("User could not be authenticated. AccessToken not found.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix()+" AccessToken not found.", ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenDtoServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenDtoServiceUnitTest.java index 5e886136..bf919335 100644 --- a/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenDtoServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/token/business/AccessTokenDtoServiceUnitTest.java @@ -48,7 +48,7 @@ void findEntityNotSuccessfully() { AccessTokenNotFoundException ex = assertThrows(AccessTokenNotFoundException.class, () -> accessTokenDtoService.findEntity(dummyToken) ); - assertEquals("AccessTokenEntity does not exist for AccessToken with userId "+userId+".", ex.getMessage()); + assertEquals(AccessTokenNotFoundException.getErrorMessagePrefix() + " UserId was " + userId, ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java index 2215b6b7..2d594c14 100644 --- a/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/user/business/UserAuthorizationServiceUnitTest.java @@ -30,17 +30,17 @@ void authenticateUserWithUsernameAndPasswordThrows() { RuntimeException ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> userAuthorizationService.authenticateUserWithUsernameAndPassword(matchesButIsNotSupportedEncoding)); - assertEquals("Request didnt meet formal requirements. Found unsupported character in header.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix() + " Found unsupported character in header.", ex.getMessage()); ex = assertThrows(RequestDidntMeetFormalRequirementsException.class, () -> userAuthorizationService.authenticateUserWithUsernameAndPassword(onlyContainsUsername)); - assertEquals("Request didnt meet formal requirements. Credentials didnt meet formal requirements.", ex.getMessage()); + assertEquals(RequestDidntMeetFormalRequirementsException.getErrorMessagePrefix() + " Credentials didnt meet formal requirements.", ex.getMessage()); when(userRepositoryMock.findByLowercaseUsernameAndPassword("user", "password")).thenReturn(null); ex = assertThrows(UserNotAuthenticatedException.class, () -> userAuthorizationService.authenticateUserWithUsernameAndPassword(matchesButUserWasNotFound)); - assertEquals("User could not be authenticated. No User found with this username and password.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix() + " No User found with this username and password.", ex.getMessage()); } @Test @@ -65,7 +65,7 @@ void authenticateUserWithRefreshTokenThrowsExceptions() { UserNotAuthenticatedException ex = assertThrows(UserNotAuthenticatedException.class, () -> userAuthorizationService.authenticateUserWithRefreshToken(authString)); - assertEquals("User could not be authenticated. No user found for this Refresh Token.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix() + " No user found for this Refresh Token.", ex.getMessage()); } @Test @@ -91,7 +91,7 @@ void authenticateUserWithAccessTokenThrows() { UserNotAuthenticatedException ex = assertThrows(UserNotAuthenticatedException.class, () -> userAuthorizationService.authenticateUserWithAccessToken(accessToken)); - assertEquals("User with the id " + userId + " could not be authenticated.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix() + " UserId was " + userId, ex.getMessage()); } @Test @@ -114,13 +114,13 @@ void authenticateUserWithAccessTokenAndGroupThrows() { UserNotAuthenticatedException ex = assertThrows(UserNotAuthenticatedException.class, () -> userAuthorizationService.authenticateUserWithAccessTokenAndGroup(accessToken, Groups.ADMIN)); - assertEquals("User with the id " + userId + " could not be authenticated.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix() + " UserId was " + userId, ex.getMessage()); when(userRepositoryMock.findByUserId(userId)).thenReturn(UserEntity.builder().groupIds(new long[]{0}).build()); ex = assertThrows(UserNotAuthenticatedException.class, () -> userAuthorizationService.authenticateUserWithAccessTokenAndGroup(accessToken, Groups.ADMIN)); - assertEquals("User could not be authenticated. Not in necessary group.", ex.getMessage()); + assertEquals(UserNotAuthenticatedException.getErrorMessagePrefix()+" Not in necessary group.", ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/user/business/UserBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/user/business/UserBusinessServiceUnitTest.java index 414a8f94..d858f0b3 100644 --- a/src/test/java/de/filefighter/rest/domain/user/business/UserBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/user/business/UserBusinessServiceUnitTest.java @@ -65,7 +65,7 @@ void getRefreshTokenForUserWithoutUser() { UserNotFoundException ex = assertThrows(UserNotFoundException.class, () -> userBusinessService.getRefreshTokenForUser(dummyUser) ); - assertEquals("Could not find user with userId " + userId + ".", ex.getMessage()); + assertEquals(UserNotFoundException.getErrorMessagePrefix() + " UserId was " + userId, ex.getMessage()); } @Test @@ -109,7 +109,7 @@ void getUserByIdThrowsExceptions() { UserNotFoundException ex = assertThrows(UserNotFoundException.class, () -> userBusinessService.getUserById(id)); - assertEquals("Could not find user with userId " + id + ".", ex.getMessage()); + assertEquals(UserNotFoundException.getErrorMessagePrefix() + " UserId was " + id, ex.getMessage()); } @Test @@ -134,7 +134,7 @@ void findUserByUsernameThrowsExceptions() { UserNotFoundException exception = assertThrows(UserNotFoundException.class, () -> userBusinessService.findUserByUsername(validFormat) ); - assertEquals("User with username '" + validFormat + "' not found.", exception.getMessage()); + assertEquals(UserNotFoundException.getErrorMessagePrefix() + " Username was " + validFormat, exception.getMessage()); } @Test @@ -195,7 +195,7 @@ void registerNewUserThrows() { userRegisterForm.setUsername(notValidUsername); UserNotRegisteredException ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Username was not valid.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix() + " Username was not valid.", ex.getMessage()); // username taken userRegisterForm.setUsername(username); @@ -204,7 +204,7 @@ void registerNewUserThrows() { ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Username already taken.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix() + " Username already taken.", ex.getMessage()); //passwords empty when(userRepositoryMock.findByLowercaseUsername(username.toLowerCase())).thenReturn(null); @@ -212,27 +212,27 @@ void registerNewUserThrows() { userRegisterForm.setPassword(""); ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Wanted to change password, but password was not valid.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix() + " Wanted to change password, but password was not valid.", ex.getMessage()); userRegisterForm.setPassword("somepassword"); userRegisterForm.setConfirmationPassword(""); ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Wanted to change password, but password was not valid.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix() + " Wanted to change password, but password was not valid.", ex.getMessage()); //Passwords not valid userRegisterForm.setConfirmationPassword(notValidPassword); userRegisterForm.setPassword(notValidPassword); ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Password needs to be at least 8 characters long and, contains at least one uppercase and lowercase letter and a number.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix() + " Password needs to be at least 8 characters long and, contains at least one uppercase and lowercase letter and a number.", ex.getMessage()); //Passwords do not match. userRegisterForm.setPassword(password); ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Passwords do not match.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix()+" Passwords do not match.", ex.getMessage()); //Username exists in password. userRegisterForm.setUsername("Password123"); @@ -240,7 +240,7 @@ void registerNewUserThrows() { ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. Username must not appear in password.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix()+" Username must not appear in password.", ex.getMessage()); // group does not exist userRegisterForm.setUsername(username); @@ -249,7 +249,7 @@ void registerNewUserThrows() { ex = assertThrows(UserNotRegisteredException.class, () -> userBusinessService.registerNewUser(userRegisterForm)); - assertEquals("User could not be registered. One or more groups do not exist.", ex.getMessage()); + assertEquals(UserNotRegisteredException.getErrorMessagePrefix()+" One or more groups do not exist.", ex.getMessage()); } @Test @@ -280,29 +280,29 @@ void updateUserThrows() { UserNotUpdatedException ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. No updates specified.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" No updates specified.", ex.getMessage()); UserRegisterForm userRegisterForm1 = UserRegisterForm.builder().build(); User authenticatedUser1 = User.builder().groups(null).build(); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm1, authenticatedUser1)); - assertEquals("User could not get updated. Authenticated User is not allowed.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Authenticated User is not allowed.", ex.getMessage()); authenticatedUser.setGroups(new Groups[]{Groups.UNDEFINED}); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm1, authenticatedUser)); - assertEquals("User could not get updated. Only Admins are allowed to update other users.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Only Admins are allowed to update other users.", ex.getMessage()); //user not found with id. authenticatedUser.setGroups(new Groups[]{Groups.ADMIN}); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm1, authenticatedUser)); - assertEquals("User could not get updated. User does not exist, use register endpoint.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" User does not exist, use register endpoint.", ex.getMessage()); when(userRepositoryMock.findByUserId(userId)).thenReturn(userEntityMock); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm1, authenticatedUser)); - assertEquals("User could not get updated. No changes were made.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" No changes were made.", ex.getMessage()); } @Test @@ -317,7 +317,7 @@ void updateUserNameThrows() { userRegisterForm.setUsername(""); UserNotUpdatedException ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. Wanted to change username, but username was not valid.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Wanted to change username, but username was not valid.", ex.getMessage()); String validUserName = "ValidUserNameButExists."; userRegisterForm.setUsername(validUserName); @@ -325,7 +325,7 @@ void updateUserNameThrows() { when(userDtoServiceMock.createDto(dummyEntity)).thenReturn(User.builder().build()); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. Username already taken.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Username already taken.", ex.getMessage()); } @Test @@ -351,25 +351,25 @@ void updatePasswordThrows() { userRegisterForm.setPassword(""); UserNotUpdatedException ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. Wanted to change password, but password was not valid.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Wanted to change password, but password was not valid.", ex.getMessage()); userRegisterForm.setPassword("somepw"); userRegisterForm.setConfirmationPassword(""); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. Wanted to change password, but password was not valid.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Wanted to change password, but password was not valid.", ex.getMessage()); userRegisterForm.setPassword("somepw"); userRegisterForm.setConfirmationPassword("somepw"); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser), "Password needs to be at least 8 characters long and, contains at least one uppercase and lowercase letter and a number."); - assertEquals("User could not get updated. Password needs to be at least 8 characters long and, contains at least one uppercase and lowercase letter and a number.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Password needs to be at least 8 characters long and, contains at least one uppercase and lowercase letter and a number.", ex.getMessage()); userRegisterForm.setPassword("Somepw12345"); userRegisterForm.setConfirmationPassword("Somepw1234"); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser), "Passwords do not match."); - assertEquals("User could not get updated. Passwords do not match.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Passwords do not match.", ex.getMessage()); String validPassword = "ValidPassword1234!="; userRegisterForm.setPassword(validPassword); @@ -377,7 +377,7 @@ void updatePasswordThrows() { when(userRepositoryMock.findByUserId(userId)).thenReturn(dummyEntity); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser), "Username must not appear in password."); - assertEquals("User could not get updated. Username must not appear in password.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Username must not appear in password.", ex.getMessage()); } @Test @@ -405,7 +405,7 @@ void updateGroupsThrows() { when(groupRepositoryMock.getGroupsByIds(groups)).thenReturn(new Groups[]{Groups.ADMIN}); UserNotUpdatedException ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. Only admins can add users to group Admin.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" Only admins can add users to group Admin.", ex.getMessage()); groups = new long[]{123032, 1230213}; userRegisterForm.setGroupIds(groups); @@ -413,7 +413,7 @@ void updateGroupsThrows() { when(groupRepositoryMock.getGroupsByIds(groups)).thenThrow(new IllegalArgumentException("id doesnt belong to a group")); ex = assertThrows(UserNotUpdatedException.class, () -> userBusinessService.updateUser(userId, userRegisterForm, authenticatedUser)); - assertEquals("User could not get updated. One or more groups do not exist.", ex.getMessage()); + assertEquals(UserNotUpdatedException.getErrorMessagePrefix()+" One or more groups do not exist.", ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/user/business/UserDtoServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/user/business/UserDtoServiceUnitTest.java index e5f19975..f4e9ca34 100644 --- a/src/test/java/de/filefighter/rest/domain/user/business/UserDtoServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/user/business/UserDtoServiceUnitTest.java @@ -50,7 +50,7 @@ void findEntityThrowsException() { UserNotFoundException ex = assertThrows(UserNotFoundException.class, () -> userDtoService.findEntity(user)); - assertEquals("Could not find user with userId 0.", ex.getMessage()); + assertEquals(UserNotFoundException.getErrorMessagePrefix()+" UserId was " + userId, ex.getMessage()); } @Test diff --git a/src/test/java/de/filefighter/rest/domain/user/group/GroupRepositoryUnitTest.java b/src/test/java/de/filefighter/rest/domain/user/group/GroupRepositoryUnitTest.java index c97c406d..e5babd7d 100644 --- a/src/test/java/de/filefighter/rest/domain/user/group/GroupRepositoryUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/user/group/GroupRepositoryUnitTest.java @@ -16,7 +16,7 @@ void getGroupByIdThrows() { long id = 900; IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> groupRepository.getGroupById(id)); - assertEquals("id " + id + " doesnt belong to a group.", ex.getMessage()); + assertEquals("GroupId " + id + " doesnt belong to a group.", ex.getMessage()); } @Test From a3f646090b3235aaabaec980788d9aa436680f85 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Sat, 26 Dec 2020 17:09:40 +0100 Subject: [PATCH 04/32] Cleanup. Implemented necessary changes to cucumber steps --- .../rest/domain/user/exceptions/UserNotUpdatedException.java | 2 +- src/test/resources/FindUser.feature | 4 ++-- src/test/resources/crudFileSystem.feature | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java index 5d2b51d5..f1b13f93 100644 --- a/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java +++ b/src/main/java/de/filefighter/rest/domain/user/exceptions/UserNotUpdatedException.java @@ -4,7 +4,7 @@ public class UserNotUpdatedException extends RuntimeException implements FileFighterException { - private static final String ERROR_MESSAGE_PREFIX = "User could not get updated"; + private static final String ERROR_MESSAGE_PREFIX = "User could not get updated."; public UserNotUpdatedException() { super(ERROR_MESSAGE_PREFIX); diff --git a/src/test/resources/FindUser.feature b/src/test/resources/FindUser.feature index f0d416e2..b9ebba8c 100644 --- a/src/test/resources/FindUser.feature +++ b/src/test/resources/FindUser.feature @@ -27,12 +27,12 @@ Feature: Find User with Username Scenario: Failed to find another user because username has spelling errors When user with accessToken "accessToken1" searches user with search-value "benguin" Then response status code is 404 - And response contains key "message" and value "User with username 'benguin' not found." + And response contains key "message" and value "User not found. Username was benguin" And response contains key "status" and value "Not Found" #kinda same but still Scenario: Failed to find another user because username does not exist When user with accessToken "accessToken1" searches user with search-value "bielefeld" Then response status code is 404 - And response contains key "message" and value "User with username 'bielefeld' not found." + And response contains key "message" and value "User not found. Username was bielefeld" And response contains key "status" and value "Not Found" \ No newline at end of file diff --git a/src/test/resources/crudFileSystem.feature b/src/test/resources/crudFileSystem.feature index 682a71bf..9e165156 100644 --- a/src/test/resources/crudFileSystem.feature +++ b/src/test/resources/crudFileSystem.feature @@ -17,11 +17,11 @@ Feature: FileSystem CRUD When user requests fileSystemInfo with fileSystemId 1234 and accessTokenValue "900000" Then response status code is 400 And response contains key "status" and value "Bad Request" - And response contains key "message" and value "FileSystemItem with id 1234 could not be found or you are not allowed to view it." + And response contains key "message" and value "FileSystemItem could not be found or you are not allowed to view it. FileSystemId was 1234" Scenario: Get FileSystemItem does not work, because user is not allowed Given fileSystemItem with the fileSystemId 1234 exists, was created by user with userId 9999999 and has the name "dummyFile.pdf" When user requests fileSystemInfo with fileSystemId 1234 and accessTokenValue "900000" Then response status code is 400 And response contains key "status" and value "Bad Request" - And response contains key "message" and value "FileSystemItem with id 1234 could not be found or you are not allowed to view it." + And response contains key "message" and value "FileSystemItem could not be found or you are not allowed to view it. FileSystemId was 1234" From 03249249cdaad6e2dfb1cbcf83a28260372f5ab1 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 27 Dec 2020 10:45:06 +0100 Subject: [PATCH 05/32] added the .feature file for deleting --- .../cucumber/ViewFolderContentsSteps.java | 24 +++- src/test/resources/ViewFolderContents.feature | 4 +- .../resources/deleteFilySystemItems.feature | 111 ++++++++++++++++++ 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/deleteFilySystemItems.feature diff --git a/src/test/java/de/filefighter/rest/cucumber/ViewFolderContentsSteps.java b/src/test/java/de/filefighter/rest/cucumber/ViewFolderContentsSteps.java index 6d24c1e6..a344420d 100644 --- a/src/test/java/de/filefighter/rest/cucumber/ViewFolderContentsSteps.java +++ b/src/test/java/de/filefighter/rest/cucumber/ViewFolderContentsSteps.java @@ -46,7 +46,7 @@ public void theResponseContainsTheFileWithIdAndName(long fsItemId, String name) for (JsonNode node : rootNode) { if (node.get("fileSystemId").asLong() == fsItemId && node.get("name").asText().equals(name) && - node.get("type").asText().equals("FOLDER")) + node.get("type").asText().equals("FOLDER")) // WTF why check for folder found = true; } assertTrue(found); @@ -60,4 +60,26 @@ public void theResponseContainsAnEmptyListForFilesAndFolders() throws JsonProces assertTrue(rootNode.isEmpty()); } + + @And("the response not contains the file with fileSystemId {long} and name {string}") + public void theResponseNotContainsTheFileWithFileSystemIdAndName(long fsItemId, String name) throws JsonProcessingException { + + ArrayNode rootNode = (ArrayNode) objectMapper.readTree(latestResponse.getBody()); + if (!rootNode.isContainerNode()) + throw new AssertionError("Response was not an Array or empty."); + + if + (rootNode.isEmpty()) { + assertTrue(true); + } else { + boolean notFound = true; + for (JsonNode node : rootNode) { + if (node.get("fileSystemId").asLong() == fsItemId && + node.get("name").asText().equals(name) && + node.get("type").asText().equals("FOLDER")) // WTF why check for folder + notFound = false; + } + assertTrue(notFound); + } + } } diff --git a/src/test/resources/ViewFolderContents.feature b/src/test/resources/ViewFolderContents.feature index 9dbe5956..1621728e 100644 --- a/src/test/resources/ViewFolderContents.feature +++ b/src/test/resources/ViewFolderContents.feature @@ -27,6 +27,8 @@ Feature: View Folder Scenario: insufficient authorization Given user 9877 exists And accessToken with value "2345678" exists for user 9877 + When user with token "2345678" wants to see the content of folder with path "/bla/fasel" + Then response status code is 400 And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." Scenario: shared folder (user) @@ -70,4 +72,4 @@ Feature: View Folder And user with the userId 1234 is allowed to VIEW the fileSystemItem with the fileSystemId 44 When user with token "900000" wants to see the content of folder with path "/empty" Then response status code is 200 - And the response contains an empty list for files and folders \ No newline at end of file + And the response contains an empty list for files and folders diff --git a/src/test/resources/deleteFilySystemItems.feature b/src/test/resources/deleteFilySystemItems.feature new file mode 100644 index 00000000..9297dc61 --- /dev/null +++ b/src/test/resources/deleteFilySystemItems.feature @@ -0,0 +1,111 @@ +Feature: FileSystem Delete + As a user i want to delete FileSystemItems. + + Background: + Given database is empty + And user 1234 exists + And accessToken with value "900000" exists for user 1234 + And fileSystemItem with the fileSystemId 42 exists, was created by user with userId 420 and has the path "/bla" + And fileSystemItem with the fileSystemId 42 is a folder and contains the fileSystemId 72 + And fileSystemItem with the fileSystemId 72 exists, was created by user with userId 420 and has the name "wow.txt" + + + Scenario: File Deletion + Given user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 72 + When user with token "900000" wants to see the content of folder with path "/bla" + Then response status code is 200 + And the response contains the file with fileSystemId 72 and name "wow.txt" + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 72 + Then response status code is 200 + When user with token "900000" wants to see the content of folder with path "/bla" + And the response contains an empty list for files and folders + + Scenario: Folder and content Deletion + Given user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 42 + And user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 72 + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 200 + When user with token "900000" wants to see the content of folder with path "/bla" + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + + Scenario: Folder and content Deletion with remaining content + Given user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 42 + And user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 72 + And fileSystemItem with the fileSystemId 1080 exists, was created by user with userId 420 and has the name "IwillStay.txt" + And user with the userId 1234 is allowed to VIEW the fileSystemItem with the fileSystemId 1080 + And fileSystemItem with the fileSystemId 42 is a folder and contains the fileSystemId 1080 + # this should addd the ID!!!!!!!! ^ or we make another step + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 200 + And response contains key "message" and value "Not everything got deleted, because you are not allowed to edit some files." + When user with token "900000" wants to see the content of folder with path "/bla" + And the response not contains the file with fileSystemId 72 and name "wow.txt" + And the response contains the file with fileSystemId 1080 and name "IwillStay.txt" + + + Scenario: Folder and content Deletion with remaining content (invisible) + And user 420 exists + And accessToken with value "2000000" exists for user 1234 + Given user with the userId 1234 is allowed to EDIT the fileSystemItem with the fileSystemId 42 + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 200 + When user with token "900000" wants to see the content of folder with path "/bla" + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + When user with token "2000000" wants to see the content of folder with path "/bla" + Then response status code is 200 + And the response contains the file with fileSystemId 72 and name "wow.txt" + + + Scenario: recursion + Given fileSystemItem with the fileSystemId 1 exists, was created by user with userId 1234 and has the path "/bla/fasel" + And fileSystemItem with the fileSystemId 42 is a folder and contains the fileSystemId 1 + And fileSystemItem with the fileSystemId 2 exists, was created by user with userId 1234 and has the name "git.exe" + And fileSystemItem with the fileSystemId 1 is a folder and contains the fileSystemId 2 + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 200 + When user with token "900000" wants to see the content of folder with path "/bla/fasel" + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + When user with token "900000" wants to see the content of folder with path "/bla" + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + + Scenario: recursion with remaining file + Given fileSystemItem with the fileSystemId 1 exists, was created by user with userId 1234 and has the path "/bla/fasel" + And fileSystemItem with the fileSystemId 42 is a folder and contains the fileSystemId 1 + And fileSystemItem with the fileSystemId 2 exists, was created by user with userId 1234 and has the name "git.exe" + And fileSystemItem with the fileSystemId 1 is a folder and contains the fileSystemId 2 + And fileSystemItem with the fileSystemId 3 exists, was created by user with userId 420 and has the name "subversion.exe" + And fileSystemItem with the fileSystemId 1 is a folder and contains the fileSystemId 3 + And user with the userId 1234 is allowed to VIEW the fileSystemItem with the fileSystemId 3 + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 200 + When user with token "900000" wants to see the content of folder with path "/bla/fasel" + Then response status code is 200 + And the response contains the file with fileSystemId 3 and name "subversion.exe" + And the response not contains the file with fileSystemId 3 and name "subversion.exe" + When user with token "900000" wants to see the content of folder with path "/bla" + Then response status code is 200 + And the response contains an empty list for files and folders + + + Scenario: insufficient authorization + Given user with the userId 1234 is allowed to VIEW the fileSystemItem with the fileSystemId 42 + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + + Scenario: insufficient permission + Given user 9877 exists + And accessToken with value "2345678" exists for user 9877 + When user with token "2345678" wants to delete the fileSystemItem with the fileSystemId 42 + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." + + + Scenario: Folder does not exist + When user with token "900000" wants to delete the fileSystemItem with the fileSystemId 42432567 + Then response status code is 400 + And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder." From e0d388ae628ff390443c7b97cb222d353ad86d91 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Sun, 27 Dec 2020 12:38:58 +0100 Subject: [PATCH 06/32] FileSystemItem now includes the User --- .../business/FileSystemBusinessService.java | 59 +++++++++++++++---- .../filesystem/data/dto/FileSystemItem.java | 3 +- .../FileSystemBusinessServiceUnitTest.java | 4 +- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java index 9a3c4436..31ffaebf 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessService.java @@ -6,6 +6,7 @@ import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemEntity; import de.filefighter.rest.domain.filesystem.data.persistence.FileSystemRepository; import de.filefighter.rest.domain.filesystem.exceptions.FileSystemContentsNotAccessibleException; +import de.filefighter.rest.domain.filesystem.exceptions.FileSystemItemCouldNotBeDeletedException; import de.filefighter.rest.domain.filesystem.exceptions.FileSystemItemNotFoundException; import de.filefighter.rest.domain.filesystem.type.FileSystemType; import de.filefighter.rest.domain.filesystem.type.FileSystemTypeRepository; @@ -98,16 +99,25 @@ public FileSystemItem getFileSystemItemInfo(long fsItemId, User authenticatedUse return createDTO(fileSystemEntity, authenticatedUser, null); } - public String removeTrailingBackSlashes(String pathToFind) { - char[] chars = pathToFind.toCharArray(); - // for the case of "/" - if (chars.length != 1 && chars[chars.length - 1] == '/') { - chars = Arrays.copyOf(chars, chars.length - 1); - return new String(chars); + public void deleteFileSystemItemById(long fsItemId, User authenticatedUser) { + FileSystemEntity fileSystemEntity = fileSystemRepository.findByFileSystemId(fsItemId); + if (null == fileSystemEntity) + throw new FileSystemItemCouldNotBeDeletedException(fsItemId); + + if (!userIsAllowedToEditFileSystemEntity(fileSystemEntity, authenticatedUser)) + throw new FileSystemItemCouldNotBeDeletedException(fsItemId); + + if (fileSystemEntity.isFile()) { + // CASE 0 - File + fileSystemRepository.delete(fileSystemEntity); + } else { + // CASE 1 - Folder + } - return pathToFind; } + // ---------------- HELPER ------------------- + public boolean userIsAllowedToSeeFileSystemEntity(FileSystemEntity fileSystemEntity, User authenticatedUser) { // user created the item if (fileSystemEntity.getCreatedByUserId() == authenticatedUser.getUserId()) @@ -131,8 +141,37 @@ public boolean userIsAllowedToSeeFileSystemEntity(FileSystemEntity fileSystemEnt return false; } - public void deleteFileSystemItemById(long fsItemId, User authenticatedUser) { - //WIP + private boolean userIsAllowedToEditFileSystemEntity(FileSystemEntity fileSystemEntity, User authenticatedUser) { + // user created the item + if (fileSystemEntity.getCreatedByUserId() == authenticatedUser.getUserId()) + return true; + + // user got the item shared. + for (long userId : fileSystemEntity.getEditableForUserIds()) { + if (userId == authenticatedUser.getUserId()) + return true; + } + + // user is in group that got the item shared. + long[] fileIsSharedToGroups = fileSystemEntity.getEditableFoGroupIds(); + for (Groups group : authenticatedUser.getGroups()) { + for (long groupId : fileIsSharedToGroups) { + if (groupId == group.getGroupId()) + return true; + + } + } + return false; + } + + public String removeTrailingBackSlashes(String pathToFind) { + char[] chars = pathToFind.toCharArray(); + // for the case of "/" + if (chars.length != 1 && chars[chars.length - 1] == '/') { + chars = Arrays.copyOf(chars, chars.length - 1); + return new String(chars); + } + return pathToFind; } public FileSystemItem createDTO(FileSystemEntity fileSystemEntity, User authenticatedUser, String basePath) { @@ -143,7 +182,7 @@ public FileSystemItem createDTO(FileSystemEntity fileSystemEntity, User authenti boolean isAFolder = type == FileSystemType.FOLDER && !fileSystemEntity.isFile(); return FileSystemItem.builder() - .createdByUserId(fileSystemEntity.getCreatedByUserId()) + .createdByUser(ownerOfFileSystemItem) .fileSystemId(fileSystemEntity.getFileSystemId()) .lastUpdated(fileSystemEntity.getLastUpdated()) .name(fileSystemEntity.getName()) diff --git a/src/main/java/de/filefighter/rest/domain/filesystem/data/dto/FileSystemItem.java b/src/main/java/de/filefighter/rest/domain/filesystem/data/dto/FileSystemItem.java index c0b9f015..1768d341 100644 --- a/src/main/java/de/filefighter/rest/domain/filesystem/data/dto/FileSystemItem.java +++ b/src/main/java/de/filefighter/rest/domain/filesystem/data/dto/FileSystemItem.java @@ -1,6 +1,7 @@ package de.filefighter.rest.domain.filesystem.data.dto; import de.filefighter.rest.domain.filesystem.type.FileSystemType; +import de.filefighter.rest.domain.user.data.dto.User; import lombok.Builder; import lombok.Data; @@ -14,7 +15,7 @@ public class FileSystemItem { private String name; private boolean isShared; private double size; - private long createdByUserId; //uploadedBy + private User createdByUser; //uploadedBy private long lastUpdated; private FileSystemType type; diff --git a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java index 8be8ef5a..ba672758 100644 --- a/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java +++ b/src/test/java/de/filefighter/rest/domain/filesystem/business/FileSystemBusinessServiceUnitTest.java @@ -148,7 +148,7 @@ void getFileSystemItemInfoWorks() { when(fileSystemRepositoryMock.findByFileSystemId(id)).thenReturn(entity); FileSystemItem fileSystemItem = fileSystemBusinessService.getFileSystemItemInfo(id, dummyUser); assertEquals(name, fileSystemItem.getName()); - assertEquals(userId, fileSystemItem.getCreatedByUserId()); + assertEquals(userId, fileSystemItem.getCreatedByUser().getUserId()); assertNull(fileSystemItem.getPath()); assertFalse(fileSystemItem.isShared()); } @@ -228,7 +228,7 @@ void createDTOWorks() { FileSystemItem actual = fileSystemBusinessService.createDTO(fileSystemEntity, authenticatedUser, basePath); - assertEquals(createdByUserId, actual.getCreatedByUserId()); + assertEquals(createdByUserId, actual.getCreatedByUser().getUserId()); assertEquals(fileSystemId, actual.getFileSystemId()); assertEquals(lastUpdated, actual.getLastUpdated()); assertEquals(name, actual.getName()); From 9dff8a492069a5356488f9b35bd0265360b4f83c Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 27 Dec 2020 16:08:12 +0100 Subject: [PATCH 07/32] fixed copy pesto, added step function --- .run/RestApplication-dev.run.xml | 2 +- .../rest/cucumber/ViewFolderContentsSteps.java | 17 +++++++++++++++++ .../resources/deleteFilySystemItems.feature | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.run/RestApplication-dev.run.xml b/.run/RestApplication-dev.run.xml index 1849ce5d..707c11ab 100644 --- a/.run/RestApplication-dev.run.xml +++ b/.run/RestApplication-dev.run.xml @@ -1,6 +1,6 @@ - +