Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit e7ab590

Browse files
FF-65 Added Cucumber Integration (#3)
* Added Cucumber Integration * fixed pipeline. * added missing $ * FF-65 added basic steps * changed Description and addded Background * fixed some typos, added some comments, created steps files removed dummy test. * cleaning of .feature file * FF-65 added bad cases for Permissions feature file * redone ViewFolderContents.feature * FF-65 cleaning of feature files, added java classes for steps. * ViewFolderContentsSteps now extends SpringIntegrationTest * added cucumber run config. * added two scenarios, fixed all the datatypes (better regenerate step functions) * regenerate step functions and remove duplicates * FF-65 fixed test failure because of duplicate step function * FF-65 fixed steps, added comments. * renamed role to group * fixed deletion of line Co-authored-by: qvalentin <[email protected]>
1 parent e02c117 commit e7ab590

File tree

13 files changed

+309
-16
lines changed

13 files changed

+309
-16
lines changed

.run/RestApplication.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="RestApplication[DEV]" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
2+
<configuration name="RestApplication[DEV]" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
33
<module name="rest" />
44
<option name="SPRING_BOOT_MAIN_CLASS" value="de.filefighter.rest.RestApplication" />
55
<option name="ACTIVE_PROFILES" value="dev" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run all Cucumber Tests" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java">
3+
<envs>
4+
<env name="SPRING_PROFILES_ACTIVE" value="&quot;dev&quot;" />
5+
</envs>
6+
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/cucumber/de/filefighter/rest" />
7+
<option name="GLUE" value="de.filefighter.rest.cucumber" />
8+
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
9+
<module name="rest" />
10+
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter" />
11+
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
12+
<method v="2">
13+
<option name="Make" enabled="true" />
14+
</method>
15+
</configuration>
16+
</component>

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<properties>
1818
<java.version>11</java.version>
19+
<cucumber.version>6.8.0</cucumber.version>
1920
</properties>
2021

2122
<dependencies>
@@ -75,6 +76,25 @@
7576
<artifactId>spring-boot-starter-test</artifactId>
7677
<scope>test</scope>
7778
</dependency>
79+
80+
<dependency>
81+
<groupId>io.cucumber</groupId>
82+
<artifactId>cucumber-java</artifactId>
83+
<version>${cucumber.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>io.cucumber</groupId>
88+
<artifactId>cucumber-junit</artifactId>
89+
<version>${cucumber.version}</version>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>io.cucumber</groupId>
94+
<artifactId>cucumber-spring</artifactId>
95+
<version>${cucumber.version}</version>
96+
<scope>test</scope>
97+
</dependency>
7898
<!-- TESTING -->
7999

80100
</dependencies>

src/main/java/de/filefighter/rest/domain/permission/data/dto/PermissionSet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package de.filefighter.rest.domain.permission.data.dto;
22

33
import de.filefighter.rest.domain.user.data.dto.User;
4-
import de.filefighter.rest.domain.user.role.Role;
4+
import de.filefighter.rest.domain.user.role.Groups;
55
import lombok.Getter;
66

77
@Getter
88
public class PermissionSet {
9-
private final Role[] visibleForRoles;
10-
private final Role[] editableForRoles;
9+
private final Groups[] visibleForRoles;
10+
private final Groups[] editableForRoles;
1111
private final User[] visibleForUsers;
1212
private final User[] editableForUsers;
1313

14-
public PermissionSet(Role[] visibleForRoles, Role[] editableForRoles, User[] visibleForUsers, User[] editableForUsers) {
14+
public PermissionSet(Groups[] visibleForRoles, Groups[] editableForRoles, User[] visibleForUsers, User[] editableForUsers) {
1515
this.visibleForRoles = visibleForRoles;
1616
this.editableForRoles = editableForRoles;
1717
this.visibleForUsers = visibleForUsers;

src/main/java/de/filefighter/rest/domain/user/data/dto/User.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package de.filefighter.rest.domain.user.data.dto;
2-
import de.filefighter.rest.domain.user.role.Role;
2+
import de.filefighter.rest.domain.user.role.Groups;
33
import lombok.Builder;
44
import lombok.Data;
55

@@ -9,9 +9,9 @@
99
public class User {
1010
private long id;
1111
private String username;
12-
private Role[] roles;
12+
private Groups[] roles;
1313

14-
public User(long id, String username, Role... roles) {
14+
public User(long id, String username, Groups... roles) {
1515
this.id = id;
1616
this.username = username;
1717
this.roles = roles;

src/main/java/de/filefighter/rest/domain/user/role/RoleRepository.java renamed to src/main/java/de/filefighter/rest/domain/user/role/GroupRepository.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
import org.springframework.stereotype.Service;
44

55
@Service
6-
public class RoleRepository {
7-
private final Role[] roles = Role.values();
6+
public class GroupRepository {
7+
private final Groups[] roles = Groups.values();
88

99
//TODO: test this.
10-
public Role getRoleById(long id) {
11-
for (Role role : roles) {
10+
public Groups getRoleById(long id) {
11+
for (Groups role : roles) {
1212
if (role.getRoleId() == id) {
1313
return role;
1414
}
1515
}
1616
throw new IllegalArgumentException("id doesnt belong to a role");
1717
}
1818

19-
public Role[] getRolesByIds(long... ids){
20-
Role[] roles = new Role[ids.length]; //TODO: check this again.
19+
public Groups[] getRolesByIds(long... ids){
20+
Groups[] roles = new Groups[ids.length]; //TODO: check this again.
2121

2222
for (int i = 0; i < ids.length; i++) {
2323
roles[i] = this.getRoleById(ids[i]);

src/main/java/de/filefighter/rest/domain/user/role/Role.java renamed to src/main/java/de/filefighter/rest/domain/user/role/Groups.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package de.filefighter.rest.domain.user.role;
22

3-
public enum Role {
3+
public enum Groups {
44
UNDEFINED(-1, "No group"),
55
FAMILY(0, "Family"),
66
ADMIN(1, "Admin");
77

88
private final long roleId;
99
private final String displayName;
1010

11-
Role(long roleId, String displayName) {
11+
Groups(long roleId, String displayName) {
1212
this.roleId = roleId;
1313
this.displayName = displayName;
1414
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Feature: View Folder
2+
As a user
3+
I want to see the content of folders and navigate in them, so they can see and interact with their uploaded and shared files.
4+
5+
Background:
6+
Given database is empty
7+
And user 1234 exists
8+
And user 1234 has access token "900000"
9+
And "folder" exists with id 42 and path "bla"
10+
And "file" exists with id 72 and path "bla/wow.txt"
11+
12+
13+
Scenario: Successful interaction
14+
Given user 1234 has permission of "view" for "folder" with id 42
15+
And user 1234 has permission of "view" for "file" with id 72
16+
When user with token "900000" wants to see the content of folder with path "bla"
17+
Then response status code is 200
18+
And the response contains the file with id 72 and name "wow.txt"
19+
20+
21+
Scenario: Folder does not exist
22+
Given user 1234 has permission of "view" for "folder" with id 42
23+
When user with token "900000" wants to see the content of folder with path "bla/fasel"
24+
Then response status code is 400
25+
And response message contains "Folder does not exist, or you are not allowed to see the folder."
26+
27+
28+
Scenario: insufficient authorization
29+
Given user 9877 exists
30+
And user 9877 has access token "2345678"
31+
When user with token "2345678" wants to see the content of folder with path "bla"
32+
Then response status code is 400
33+
And response message contains "Folder does not exist, or you are not allowed to see the folder."
34+
35+
Scenario: shared file
36+
Given "folder" exists with id 43 and path "bla"
37+
And "file" exists with id 73 and path "bla/wow.txt"
38+
And user 1234 is owner of file or folder with id 42
39+
And user 1234 is owner of file or folder with id 72
40+
And user 1234 has permission of "view" for "folder" with id 43
41+
And user 1234 has permission of "view" for "file" with id 73
42+
When user with token "900000" wants to see the content of folder with path "bla"
43+
Then response status code is 200
44+
And the response contains the file with id 72 and name "wow.txt"
45+
And the response contains the file with id 73 and name "wow.txt"
46+
47+
Scenario: empty directory
48+
Given "folder" exists with id 44 and path "empty"
49+
And user 1234 has permission of "view" for "folder" with id 44
50+
When user with token "900000" wants to see the content of folder with path "empty"
51+
Then response status code is 200
52+
And the response contains an empty list for files and folders
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Feature: CRUD Permissions
2+
As a user and owner a file
3+
I want want to be able to give or revoke other users permissions to either see or see and edit certain files or folders, so they can work together on the same files
4+
5+
6+
Background:
7+
Given database is empty
8+
And user 1234 exists
9+
And user 9877 exists
10+
And user 1234 has access token "900000"
11+
And user 9877 has access token "2345678"
12+
13+
14+
Scenario Outline: Successful interaction for changing existing permission
15+
Given "<type>" exists with id <id> and path "<path>"
16+
And user 1234 is owner of file or folder with id <id>
17+
And user 9877 has permission of "<old_permission>" for "<type>" with id <id>
18+
When user with token "900000" wants to change permissions of "<type>" with id <id> for user with id 9877 to "<new_permission>"
19+
Then response status code is <status_code>
20+
And user 9877 has permission of "<new_permission>" for "<type>" with id <id>
21+
Examples:
22+
| type | id | path | old_permission | new_permission | status_code |
23+
| file | 12 | bar.txt | edit | view | 200 |
24+
| folder | 11 | f | edit | view | 200 |
25+
| folder | 11 | f | view | edit | 200 |
26+
| folder | 11 | f | view | view | 304 |
27+
| file | 11 | f.txt | edit | edit | 304 |
28+
29+
30+
Scenario Outline: Successful interaction for removing existing permission
31+
Given "<type>" exists with id <id> and path "<path>"
32+
And user 1234 is owner of file or folder with id <id>
33+
And user 9877 has permission of "<old_permission>" for "<type>" with id <id>
34+
When user with token "900000" wants to remove permissions of "<type>" with id <id> for user 9877
35+
Then response status code is <status_code>
36+
And user with id 9877 has no permission for "<type>" with id <id>
37+
Examples:
38+
| type | id | path | old_permission | status_code |
39+
| file | 12 | fo.c | view | 200 |
40+
| folder | 11 | f | view | 200 |
41+
| file | 10 | f.c | edit | 200 |
42+
| folder | 10 | fc | edit | 200 |
43+
44+
45+
Scenario: removing not existing permission
46+
Given "file" exists with id 111 and path "bla.txt"
47+
And user 1234 is owner of file or folder with id 111
48+
And user 9877 has no permission for "file" with id 111
49+
When user with token "900000" wants to remove permissions of "file" with id 111 for user 9877
50+
Then response status code is 400
51+
Then response message contains "Couldn't remove permission that does not exit."
52+
53+
54+
Scenario Outline: Successful interaction adding new permission
55+
Given "<type>" exists with id <id> and path "<path>"
56+
And user 1234 is owner of file or folder with id <id>
57+
And user 9877 has no permission for "<type>" with id <id>
58+
When user with token "900000" wants to add permissions of "<type>" with id <id> for user 9877 for "<new_permission>"
59+
Then response status code is 200
60+
And user 9877 has permission of "<new_permission>" for "<type>" with id <id>
61+
Examples:
62+
| type | id | path | new_permission |
63+
| file | 12 | f.c | edit |
64+
| file | 12 | f.c | view |
65+
| folder | 21 | f | edit |
66+
| folder | 22 | fd | view |
67+
68+
69+
Scenario: User is not owner of file
70+
Given "file" exists with id 111 and path "bla.txt"
71+
And user 3131 exists
72+
And user 9877 is owner of file or folder with id 111
73+
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
74+
Then response status code is 403
75+
And response message contains "User with id 1234 is not owner of file with id 111."
76+
77+
78+
Scenario: User does not exist
79+
Given "file" exists with id 111 and path "bla.txt"
80+
And user 1234 is owner of file or folder with id 111
81+
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
82+
Then response status code is 404
83+
And response message contains "User 3131 does not exist."
84+
85+
86+
Scenario: File does not exist
87+
And user 1234 is owner of file or folder with id 111
88+
When user with token "900000" wants to add permissions of "file" with id 111 for user 9877 for "edit"
89+
Then response status code is 404
90+
And response message contains "No File with id 111 found."
91+
92+
93+
Scenario: User is already owner
94+
Given "file" exists with id 111 and path "bla.txt"
95+
And user 1234 is owner of file or folder with id 111
96+
When user with token "900000" wants to add permissions of "file" with id 111 for user 1234 for "edit"
97+
Then response status code is 405
98+
And response message contains "User with id 1234 is already owner of file with id 111."
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package de.filefighter.rest.cucumber;
2+
3+
import io.cucumber.java.en.And;
4+
import io.cucumber.java.en.Given;
5+
import io.cucumber.java.en.Then;
6+
import io.cucumber.java.en.When;
7+
8+
public class CrudPermissionSteps extends SpringIntegrationTest{
9+
10+
// TODO: Rearrange the steps, create Shared State Handler.
11+
12+
@Given("database is empty")
13+
public void databaseIsEmpty() {
14+
}
15+
16+
@And("user {int} exists")
17+
public void userExists(int arg0) {
18+
}
19+
20+
@And("user {int} has access token {string}")
21+
public void userHasAccessToken(int arg0, String arg1) {
22+
}
23+
24+
@And("user {int} has permission of {string} for {string} with id {int}")
25+
public void userHasPermissionOfForWithIdId(int arg0, String arg1, String arg2,int arg3) {
26+
}
27+
28+
@When("user with token {string} wants to change permissions of {string} with id {int} for user with id {int} to {string}")
29+
public void userWithTokenWantsToChangePermissionsOfWithIdIdForUserWithIdTo(String arg0, String arg1, int fileID,int arg2, String arg3) {
30+
}
31+
32+
@When("user with token {string} wants to remove permissions of {string} with id {int} for user {int}")
33+
public void userWithTokenWantsToRemovePermissionsOfWithIdIdForUser(String arg0, String arg1,int fileID, int arg2) {
34+
}
35+
36+
@And("user with id {int} has no permission for {string} with id {int}")
37+
public void userWithIdHasNoPermissionForWithIdId(int arg0, String arg1, int fileID) {
38+
}
39+
40+
@Given("{string} exists with id {int} and path {string}")
41+
public void existsWithIdAndPath(String arg0, int arg1, String arg2) {
42+
}
43+
44+
@And("user {int} is owner of file or folder with id {int}")
45+
public void userIsOwnerOfFileOrFolderWithId(int arg0, int arg1) {
46+
}
47+
48+
@And("user {int} has no permission for {string} with id {int}")
49+
public void userHasNoPermissionForWithId(int arg0, String arg1, int arg2) {
50+
}
51+
52+
@Then("response status code is {int}")
53+
public void responseStatusCodeIs(int arg0) {
54+
}
55+
56+
@Then("response message contains {string}")
57+
public void responseMessageContains(String arg0) {
58+
}
59+
60+
@When("user with token {string} wants to add permissions of {string} with id {int} for user {int} for {string}")
61+
public void userWithTokenWantsToAddPermissionsOfWithIdForUserFor(String arg0, String arg1, int arg2, int arg3, String arg4) {
62+
}
63+
64+
}

0 commit comments

Comments
 (0)