forked from cucumber/cucumber-java-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSharesSteps.java
232 lines (213 loc) · 10.2 KB
/
SharesSteps.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**
* ownCloud Android Scenario Tests
*
* @author Jesús Recio Rincón (@jesmrec)
*/
package io.cucumber;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.logging.Level;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.ParameterType;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import utils.entities.OCShare;
import utils.log.Log;
public class SharesSteps {
private World world;
public SharesSteps(World world) {
this.world = world;
}
@ParameterType("user|group")
public String usertype(String type){
return type;
}
@ParameterType("shared|reshared")
public int sharelevel(String type){
if (type.equals("shared")) {
return 0; //share, first level
} else {
return 1; //reshare
}
}
@Given("{word} has {sharelevel} {itemtype} {word} with {word} with permissions {word}")
public void user_has_shared_item_with_permissions(String sharingUser, int shareLevel, String type, String itemName,
String recipientUser, String permissions) throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.shareAPI.createShare(sharingUser, itemName, recipientUser, "0", permissions, "", "", shareLevel);
world.shareAPI.acceptAllShares("user", recipientUser);
}
@When("Alice selects {usertype} {word} as sharee")
public void user_selects_sharee(String type, String sharee)
throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.addPrivateShare();
world.searchShareePage.shareWithUser(sharee);
world.shareAPI.acceptAllShares(type,sharee);
}
@When("Alice edits the share on {itemtype} {word} with permissions {word}")
public void user_edits_share_with_permissions(String type, String itemName, String permissions) {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.openPrivateShare(itemName);
int permissionsToInt = Integer.parseInt(permissions);
String permissionsToString = String.format("%5s", Integer.toBinaryString(permissionsToInt))
.replace(" ", "0");
Log.log(Level.FINE, "Permissions converted: " + permissionsToString);
for (int i = 0; i <= permissionsToString.length() - 1; i++) {
switch (i) {
case (0): { //Share. Permission not used since resharing not enabled anymore
break;
}
case (1): { //Delete
if (type.equalsIgnoreCase("folder")) {
Log.log(Level.FINE, "Check Delete");
char status = permissionsToString.charAt(i);
boolean enabled = world.privateSharePage.isDeleteSelected();
Log.log(Level.FINE, "Status: " + status + ". Enabled: " + enabled);
if (enabled != (status == '1'))
world.privateSharePage.switchDelete();
}
break;
}
case (2): { //Create
if (type.equalsIgnoreCase("folder")) {
Log.log(Level.FINE, "Check Create");
char status = permissionsToString.charAt(i);
boolean enabled = world.privateSharePage.isCreateSelected();
Log.log(Level.FINE, "Status: " + status + ". Enabled: " + enabled);
if (enabled != (status == '1'))
world.privateSharePage.switchCreate();
}
break;
}
case (3): { //Change/Update
Log.log(Level.FINE, "Check Change");
char status = permissionsToString.charAt(i);
if (type.equalsIgnoreCase("folder")) {
boolean enabled = world.privateSharePage.isChangeSelected();
Log.log(Level.FINE, "Status Folder: " + status + ". Enabled: " + enabled);
if (enabled != (status == '1')) {
world.privateSharePage.switchChange();
}
} else if (type.equalsIgnoreCase("file")) {
boolean enabled = world.privateSharePage.isEditFileEnabled();
Log.log(Level.FINE, "Status File: " + status + ". Enabled: " + enabled);
if (enabled != (status == '1')) {
world.privateSharePage.switchEditFile();
}
}
break;
}
default:
break;
}
}
world.privateSharePage.close();
}
@When("Alice deletes the share")
public void user_deletes_share() {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.deletePrivateShare();
world.sharePage.acceptDeletion();
}
@When("Alice closes share view")
public void user_closes_shares_view() {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.close();
}
@Then("share should be created/edited on {word} with the following fields")
public void share_should_be_created_with_fields(String itemName, DataTable table)
throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
//Asserts in UI
List<List<String>> listItems = table.asLists();
for (List<String> rows : listItems) {
switch (rows.get(0)) {
case "sharee": {
assertTrue(world.sharePage.isItemInListPrivateShares(rows.get(1)));
break;
}
case "group": {
assertTrue(world.sharePage.isItemInListPrivateShares(rows.get(1) + " (group)"));
break;
}
case "permissions": {
world.sharePage.openPrivateShare(itemName);
switch (rows.get(1)) {
case ("1"): { //only read
Log.log(Level.FINE, "Only read");
assertTrue(!world.privateSharePage.isEditEnabled());
break;
}
case ("3"): { //edit
Log.log(Level.FINE, "Edit");
Log.log(Level.FINE, Boolean.toString(world.privateSharePage.isEditEnabled()));
assertTrue(world.privateSharePage.isEditEnabled());
break;
}
case ("9"): { //delete
Log.log(Level.FINE, "Delete");
assertTrue(!world.privateSharePage.isCreateSelected() &&
!world.privateSharePage.isChangeSelected() &&
world.privateSharePage.isDeleteSelected());
break;
}
case ("13"): { //delete and create
Log.log(Level.FINE, "Delete and Create");
assertTrue(world.privateSharePage.isCreateSelected() &&
!world.privateSharePage.isChangeSelected() &&
world.privateSharePage.isDeleteSelected());
break;
}
default:
break;
}
}
default:
break;
}
}
//Asserts in server via API
OCShare share = world.shareAPI.getShare(itemName);
assertTrue(world.sharePage.isShareCorrect(share, listItems));
}
@Then("{word} should not have access to {word}")
public void sharee_should_not_have_access_to_item(String userName, String itemName)
throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
assertFalse(world.shareAPI.isSharedWithMe(itemName, userName, false));
}
@Then("{usertype} {word} should have access to {word}")
public void sharee_should_not_have_access_the_item(String type, String shareeName, String itemName)
throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
if (type.equalsIgnoreCase("user")) {
assertTrue(world.shareAPI.isSharedWithMe(itemName, shareeName, false));
} else if (type.equalsIgnoreCase("group")) {
assertTrue(world.shareAPI.isSharedWithMe(itemName, shareeName, true));
}
}
@Then("{word} should not be shared anymore with {word}")
public void item_should_not_be_shared_with(String itemName, String sharee)
throws Throwable {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
assertFalse(world.sharePage.isItemInListPrivateShares(sharee));
}
@Then("Alice should see {word} as recipient")
public void user_should_see_recipient(String sharee) {
String stepName = new Object(){}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
assertTrue(world.privateSharePage.isSharee(sharee));
}
}