Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CommandLineRunner initDataBaseProd(UserRepository userRepository, FileSystemRepo
LOG.info("Preloading default fsStructure: {}.", fileSystemRepository.save(FileSystemEntity
.builder()
.createdByUserId(0)
.id(0)
.fileSystemId(0)
.isFile(false)
.path("/")
.itemIds(new long[0])
Expand Down Expand Up @@ -145,7 +145,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
LOG.info("Preloading default fsItems: {} {}.",
fileSystemRepository.save(FileSystemEntity.builder()
.createdByUserId(0)
.id(0)
.fileSystemId(0)
.isFile(false)
.path("/")
.itemIds(new long[]{1})
Expand All @@ -157,7 +157,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
.build()),
fileSystemRepository.save(FileSystemEntity.builder()
.createdByUserId(0)
.id(1)
.fileSystemId(1)
.isFile(true)
.lastUpdated(Instant.now().getEpochSecond())
.name("dummyFile.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class File extends FileSystemItem{
public File() {
}

public File(long id, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet) {
super(id, name, size, createdByUserId, lastUpdated, type, permissionSet);
public File(long fileSystemId, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet) {
super(fileSystemId, name, size, createdByUserId, lastUpdated, type, permissionSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
@Setter
public class FileSystemItem {
private long id;
private long fileSystemId;
private String name;
private double size;
private long createdByUserId; //uploadedBy
Expand All @@ -19,8 +19,8 @@ public class FileSystemItem {
protected FileSystemItem() {
}

public FileSystemItem(long id, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet) {
this.id = id;
public FileSystemItem(long fileSystemId, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet) {
this.fileSystemId = fileSystemId;
this.name = name;
this.size = size;
this.createdByUserId = createdByUserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Folder extends FileSystemItem {
public Folder() {
}

public Folder(long id, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet, String path) {
super(id, name, size, createdByUserId, lastUpdated, type, permissionSet);
public Folder(long fileSystemId, String name, double size, long createdByUserId, long lastUpdated, FileSystemType type, PermissionSet permissionSet, String path) {
super(fileSystemId, name, size, createdByUserId, lastUpdated, type, permissionSet);
this.path = path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FileSystemEntity {

@MongoId
private String mongoId;
private long id;
private long fileSystemId;
private String name;
private String path;
private long typeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

@Service
public interface FileSystemRepository extends MongoRepository<FileSystemEntity, String> {
FileSystemEntity findById(long id);
FileSystemEntity findByFileSystemId(long fileSystemId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AccessTokenBusinessService(AccessTokenRepository accessTokenRepository, A
}

public AccessToken getValidAccessTokenForUser(User user) {
long userId = user.getId();
long userId = user.getUserId();
AccessTokenEntity accessTokenEntity = accessTokenRepository.findByUserId(userId);
long currentTimeSeconds = Instant.now().getEpochSecond();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public User getUserById(long userId) {
}

public RefreshToken getRefreshTokenForUser(User user) {
UserEntity userEntity = userRepository.findByUserIdAndUsername(user.getId(), user.getUsername());
UserEntity userEntity = userRepository.findByUserIdAndUsername(user.getUserId(), user.getUsername());
if (null == userEntity)
throw new UserNotFoundException(user.getId());
throw new UserNotFoundException(user.getUserId());

String refreshTokenValue = userEntity.getRefreshToken();

Expand Down Expand Up @@ -157,7 +157,7 @@ public void updateUser(long userId, UserRegisterForm userToUpdate, User authenti
throw new UserNotUpdatedException("Authenticated User is not allowed.");

boolean authenticatedUserIsAdmin = Arrays.stream(authenticatedUser.getGroups()).anyMatch(g -> g == Groups.ADMIN);
if (userId != authenticatedUser.getId() && !authenticatedUserIsAdmin)
if (userId != authenticatedUser.getUserId() && !authenticatedUserIsAdmin)
throw new UserNotUpdatedException("Only Admins are allowed to update other users.");

UserEntity userEntityToUpdate = userRepository.findByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public UserDtoService(GroupRepository groupRepository, UserRepository userReposi
public User createDto(UserEntity entity) {
return User
.builder()
.id(entity.getUserId())
.userId(entity.getUserId())
.username(entity.getUsername())
.groups(groupRepository.getGroupsByIds(entity.getGroupIds()))
.build();
}

@Override
public UserEntity findEntity(User dto) {
UserEntity userEntity = userRepository.findByUserIdAndUsername(dto.getId(), dto.getUsername());
UserEntity userEntity = userRepository.findByUserIdAndUsername(dto.getUserId(), dto.getUsername());
if (null == userEntity)
throw new UserNotFoundException(dto.getId());
throw new UserNotFoundException(dto.getUserId());

return userEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
@Data
@Builder
public class User {
private long id;
private long userId;
private String username;
private Groups[] groups;

public User(long id, String username, Groups... groups) {
this.id = id;
public User(long userId, String username, Groups... groups) {
this.userId = userId;
this.username = username;
this.groups = groups;
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/de/filefighter/rest/cucumber/CommonCucumberSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void userExists(long userId) {
.build()));
}

@And("user with id {long} exists and has username {string}, password {string} and refreshToken {string}")
@And("user with userId {long} exists and has username {string}, password {string} and refreshToken {string}")
public void userWithIdExistsAndHasUsernamePasswordAndRefreshToken(long userId, String username, String password, String refreshTokenValue) {
LOG.info("Creating User: " + userRepository.save(UserEntity
.builder()
Expand All @@ -68,7 +68,7 @@ public void userWithIdExistsAndHasUsernamePasswordAndRefreshToken(long userId, S
.build()));
}

@And("user with id {long} exists and has username {string}, password {string}")
@And("user with userId {long} exists and has username {string}, password {string}")
public void userWithIdExistsAndHasUsernamePassword(long userId, String username, String password) {
LOG.info("Creating User: " + userRepository.save(UserEntity
.builder()
Expand All @@ -82,7 +82,7 @@ public void userWithIdExistsAndHasUsernamePassword(long userId, String username,
@Autowired
MongoTemplate mongoTemplate;

@And("user with id {long} is in group with id {long}")
@And("user with userId {long} is in group with groupId {long}")
public void userWithIdIsInGroupWithId(long userId, long groupId) {
Query query = new Query();
Update newUpdate = new Update().set("groupIds", new long[]{groupId});
Expand All @@ -92,7 +92,7 @@ public void userWithIdIsInGroupWithId(long userId, long groupId) {
}

// This step almost needs a unit test.
@Given("{string} exists with id {long} and path {string}")
@Given("{string} exists with fileSystemId {long} and path {string}")
public void fileOrFolderExistsWithIdAndPath(String fileOrFolder, long fsItemId, String path) {
String[] names = path.split("/");
StringBuilder completeFilePath = new StringBuilder("/");
Expand Down Expand Up @@ -126,14 +126,14 @@ public void fileOrFolderExistsWithIdAndPath(String fileOrFolder, long fsItemId,
fileSystemRepository.save(FileSystemEntity
.builder()
.isFile(true)
.id(fsItemId)
.fileSystemId(fsItemId)
.build());
} else if (fileOrFolder.equals("folder")) {
completeFilePath.append(names[i]).append("/");
fileSystemRepository.save(FileSystemEntity
.builder()
.isFile(false)
.id(fsItemId)
.fileSystemId(fsItemId)
.path(completeFilePath.toString())
.build());
} else {
Expand All @@ -144,9 +144,9 @@ public void fileOrFolderExistsWithIdAndPath(String fileOrFolder, long fsItemId,
}
}

@And("user {long} is owner of file or folder with id {long}")
@And("user {long} is owner of file or folder with fileSystemId {long}")
public void userIsOwnerOfFileOrFolderWithId(long userId, long fsItemId) {
FileSystemEntity fileSystemEntity = fileSystemRepository.findById(fsItemId);
FileSystemEntity fileSystemEntity = fileSystemRepository.findByFileSystemId(fsItemId);

fileSystemEntity.setCreatedByUserId(userId);
fileSystemRepository.save(fileSystemEntity);
Expand All @@ -161,10 +161,10 @@ public void responseContainsKeyAndValue(String key, String value) throws JsonPro
assertEquals(value, actualValue);
}

@And("response contains the user with id {long}")
@And("response contains the user with userId {long}")
public void responseContainsTheUserWithId(long userId) throws JsonProcessingException {
JsonNode rootNode = objectMapper.readTree(latestResponse.getBody());
long actualValue = rootNode.get("id").asLong();
long actualValue = rootNode.get("userId").asLong();

assertEquals(userId, actualValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public void responseContainsValidAccessTokenForUser(long userId) throws JsonProc
assertEquals(userId, actualUserId);
}

@And("response contains refreshToken {string} and the user with id {long}")
@And("response contains refreshToken {string} and the user with userId {long}")
public void responseContainsRefreshTokenAndTheUserWithId(String refreshToken, long userId) throws JsonProcessingException {
JsonNode rootNode = objectMapper.readTree(latestResponse.getBody());
String actualRefreshToken = rootNode.get("tokenValue").asText();
JsonNode userNode = rootNode.get("user");
long actualUserId = userNode.get("id").asLong();
long actualUserId = userNode.get("userId").asLong();

assertEquals(userId, actualUserId);
assertEquals(refreshToken, actualRefreshToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.filefighter.rest.cucumber;

import de.filefighter.rest.RestApplicationIntegrationTest;
import de.filefighter.rest.TestUtils;
import io.cucumber.java.en.When;
import org.springframework.http.HttpMethod;

Expand All @@ -11,6 +10,7 @@
import static de.filefighter.rest.configuration.RestConfiguration.*;

public class UserEditInformationSteps extends RestApplicationIntegrationTest {

@When("user requests change of username with value {string} userId {long} and accessToken {string}")
public void userRequestsChangeOfUsernameWithValueAndAccessTokenAndId(String newUsername, long userId, String accessToken) {
String authHeaderString = AUTHORIZATION_BEARER_PREFIX + accessToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import io.cucumber.java.en.When;

public class ViewFolderContentsSteps extends RestApplicationIntegrationTest {

@When("user with token {string} wants to see the content of folder with path {string}")
public void userWithTokenWantsToSeeTheContentOfFolderWithPath(String accessTokenValue, String path) {
}

@And("the response contains the file with id {long} and name {string}")
@And("the response contains the file with fileSystemId {long} and name {string}")
public void theResponseContainsTheFileWithIdAndName(long fsItemId , String name) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void setUp() {
@Test
void getValidAccessTokenForUserWhenNoTokenExists() {
long dummyId = 1234;
User dummyUser = User.builder().id(dummyId).build();
User dummyUser = User.builder().userId(dummyId).build();
AccessToken dummyAccessToken = AccessToken.builder().userId(dummyId).build();
AccessTokenEntity dummyAccessTokenEntity = AccessTokenEntity.builder().userId(dummyId).build();

Expand All @@ -45,7 +45,7 @@ void getValidAccessTokenForUserWhenNoTokenExists() {
@Test
void getValidAccessTokenForUserWhenTokenExists() {
long dummyId = 1234;
User dummyUser = User.builder().id(dummyId).build();
User dummyUser = User.builder().userId(dummyId).build();
AccessToken dummyAccessToken = AccessToken.builder().userId(dummyId).build();
AccessTokenEntity dummyAccessTokenEntity = AccessTokenEntity
.builder()
Expand All @@ -63,7 +63,7 @@ void getValidAccessTokenForUserWhenTokenExists() {
@Test
void getValidAccessTokenForUserWhenTokenExistsButIsInvalid() {
long dummyId = 1234;
User dummyUser = User.builder().id(dummyId).build();
User dummyUser = User.builder().userId(dummyId).build();
AccessToken dummyAccessToken = AccessToken.builder().userId(dummyId).build();
AccessTokenEntity dummyAccessTokenEntity = AccessTokenEntity
.builder()
Expand All @@ -85,7 +85,7 @@ void getValidAccessTokenForUserWhenTokenExistsButIsInvalid() {
@Test
void getValidAccessTokenForUserWhenTokenDeletionFails() {
long dummyId = 1234;
User dummyUser = User.builder().id(dummyId).build();
User dummyUser = User.builder().userId(dummyId).build();
AccessTokenEntity dummyAccessTokenEntity = AccessTokenEntity
.builder()
.userId(dummyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void getRefreshTokenForUserWithoutUser() {
long userId = 420;
String username = "someString";

User dummyUser = User.builder().id(userId).username(username).build();
User dummyUser = User.builder().userId(userId).username(username).build();

when(userRepositoryMock.findByUserIdAndUsername(userId, username)).thenReturn(null);

Expand All @@ -74,7 +74,7 @@ void getRefreshTokenForUserWithInvalidString() {
long userId = 420;
String username = "someString";

User dummyUser = User.builder().id(userId).username(username).build();
User dummyUser = User.builder().userId(userId).username(username).build();
UserEntity dummyEntity = UserEntity.builder().refreshToken(invalidString).build();

when(userRepositoryMock.findByUserIdAndUsername(userId, username)).thenReturn(dummyEntity);
Expand All @@ -91,7 +91,7 @@ void getCorrectRefreshTokenForUser() {
long userId = 420;
String username = "someString";
String refreshToken = "someToken";
User dummyUser = User.builder().id(userId).username(username).build();
User dummyUser = User.builder().userId(userId).username(username).build();
UserEntity dummyEntity = UserEntity.builder().refreshToken(refreshToken).build();
RefreshToken expected = RefreshToken.builder().tokenValue(refreshToken).user(dummyUser).build();

Expand Down Expand Up @@ -300,7 +300,7 @@ void updateUserThrows() {
void updateUserNameThrows() {
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();
UserEntity dummyEntity = UserEntity.builder().build();

when(userRepositoryMock.findByUserId(userId)).thenReturn(userEntityMock);
Expand All @@ -323,7 +323,7 @@ void updateUserNameThrows() {
void updateUserNameWorks() {
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().username("newUserName").build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();

when(userRepositoryMock.findByUserId(userId)).thenReturn(userEntityMock);

Expand All @@ -334,7 +334,7 @@ void updateUserNameWorks() {
void updatePasswordThrows() {
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();
UserEntity dummyEntity = UserEntity.builder().userId(userId).lowercaseUsername("password").build();

when(userRepositoryMock.findByUserId(userId)).thenReturn(userEntityMock);
Expand Down Expand Up @@ -376,7 +376,7 @@ void updatePasswordWorks() {
String password = "validPassword1234";
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().password(password).confirmationPassword(password).build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();
UserEntity dummyEntity = UserEntity.builder().userId(userId).lowercaseUsername("UGABUGA").build();

when(userRepositoryMock.findByUserId(userId)).thenReturn(dummyEntity);
Expand All @@ -387,7 +387,7 @@ void updatePasswordWorks() {
void updateGroupsThrows() {
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();
UserEntity dummyEntity = UserEntity.builder().userId(userId).lowercaseUsername("password").build();

long[] groups = new long[]{0};
Expand All @@ -411,7 +411,7 @@ void updateGroupsThrows() {
void updateGroupsWorks() {
final UserRegisterForm userRegisterForm = UserRegisterForm.builder().build();
long userId = 420;
User authenticatedUser = User.builder().id(userId).groups(new Groups[]{Groups.FAMILY}).build();
User authenticatedUser = User.builder().userId(userId).groups(new Groups[]{Groups.FAMILY}).build();
UserEntity dummyEntity = UserEntity.builder().userId(userId).lowercaseUsername("password").build();

long[] groups = new long[]{0};
Expand Down
Loading