/
SynchronizationTests.java
401 lines (335 loc) · 16.2 KB
/
SynchronizationTests.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/**
* Copyright (c) 2010-2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.testing.schrodinger.scenarios;
import com.codeborne.selenide.Selenide;
import com.evolveum.midpoint.schrodinger.MidPoint;
import com.evolveum.midpoint.schrodinger.component.user.UserProjectionsTab;
import com.evolveum.midpoint.schrodinger.page.resource.ListResourcesPage;
import com.evolveum.midpoint.schrodinger.page.task.EditTaskPage;
import com.evolveum.midpoint.schrodinger.page.task.ListTasksPage;
import com.evolveum.midpoint.schrodinger.page.user.ListUsersPage;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.evolveum.midpoint.testing.schrodinger.TestBase;
import javax.naming.ConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
/**
* Created by matus on 5/21/2018.
*/
public class SynchronizationTests extends TestBase {
private static File CSV_TARGET_FILE;
private static final Logger LOG = LoggerFactory.getLogger(SynchronizationTests.class);
private static final File CSV_INITIAL_SOURCE_FILE = new File("./src/test/resources/midpoint-groups-authoritative-initial.csv");
private static final File CSV_UPDATED_SOURCE_FILE = new File("./src/test/resources/midpoint-groups-authoritative-updated.csv");
private static final String RESOURCE_AND_SYNC_TASK_SETUP_DEPENDENCY = "setUpResourceAndSynchronizationTask";
private static final String NEW_USER_AND_ACCOUNT_CREATED_DEPENDENCY = "newResourceAccountUserCreated";
private static final String NEW_USER_ACCOUNT_CREATED_LINKED_DEPENDENCY = "newResourceAccountCreatedLinked";
private static final String LINKED_USER_ACCOUNT_MODIFIED = "alreadyLinkedResourceAccountModified";
private static final String LINKED_USER_ACCOUNT_DELETED = "alreadyLinkedResourceAccountDeleted";
private static final String RESOURCE_ACCOUNT_CREATED_WHEN_UNREACHABLE = "resourceAccountCreatedWhenResourceUnreachable";
private static final String FILE_RESOUCE_NAME = "midpoint-advanced-sync.csv";
private static final String DIRECTORY_CURRENT_TEST = "synchronizationTests";
@Test(priority = 0)
public void setUpResourceAndSynchronizationTask() throws ConfigurationException, IOException {
initTestDirectory(DIRECTORY_CURRENT_TEST);
CSV_TARGET_FILE = new File(CSV_TARGET_DIR, FILE_RESOUCE_NAME);
FileUtils.copyFile(CSV_INITIAL_SOURCE_FILE,CSV_TARGET_FILE);
importObject(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_FILE,true);
importObject(ScenariosCommons.USER_TEST_RAPHAEL_FILE,true);
//changeResourceFilePath(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME, ScenariosCommons.CSV_SOURCE_OLDVALUE, CSV_TARGET_FILE.getAbsolutePath(), true);
changeResourceAttribute(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME, ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, CSV_TARGET_FILE.getAbsolutePath(), true);
refreshResourceSchema(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME);
ListResourcesPage listResourcesPage = basicPage.listResources();
listResourcesPage
.table()
.clickByName(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.clickAccountsTab()
.liveSyncTask()
.clickCreateNew()
.basicTable()
.addAttributeValue("Task name","LiveSyncTest")
.and()
.schedulingTable()
.clickCheckBox("Recurring task")
.addAttributeValue("Schedule interval (seconds)","1")
.and()
.clickSave()
.feedback()
.isSuccess();
}
@Test (priority = 1, dependsOnMethods = {RESOURCE_AND_SYNC_TASK_SETUP_DEPENDENCY})
public void newResourceAccountUserCreated() throws IOException {
FileUtils.copyFile(ScenariosCommons.CSV_SOURCE_FILE,CSV_TARGET_FILE);
Selenide.sleep(3000);
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertTrue(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.currentTableContains(ScenariosCommons.TEST_USER_DON_NAME)
);
}
@Test (priority = 2, dependsOnMethods = {NEW_USER_AND_ACCOUNT_CREATED_DEPENDENCY})
public void protectedAccountAdded(){
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertFalse(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_PROTECTED_NAME)
.updateSearch()
.and()
.currentTableContains(ScenariosCommons.TEST_USER_PROTECTED_NAME)
);
ListResourcesPage resourcesPage = basicPage.listResources();
Assert.assertTrue(
resourcesPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.clickAccountsTab()
.clickSearchInResource()
.table()
.currentTableContains(ScenariosCommons.TEST_USER_PROTECTED_NAME)
);
}
@Test (priority = 3, dependsOnMethods = {NEW_USER_AND_ACCOUNT_CREATED_DEPENDENCY})
public void newResourceAccountCreatedLinked() throws IOException {
ListUsersPage usersPage = basicPage.listUsers();
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.TEST_USER_DON_NAME)
.selectTabProjections()
.table()
.selectHeaderCheckBox()
.and()
.clickHeaderActionDropDown()
.delete()
.clickYes()
.and()
.and()
.clickSave()
.feedback()
.isSuccess();
FileUtils.copyFile(ScenariosCommons.CSV_SOURCE_FILE,CSV_TARGET_FILE);
Selenide.sleep(MidPoint.TIMEOUT_LONG_1_M);
LOG.info("Copied data to csv file, {}", Files.readString(CSV_TARGET_FILE.toPath(), StandardCharsets.US_ASCII));
ListTasksPage tasksPage = basicPage.listTasks();
EditTaskPage taskPage = tasksPage.table().clickByName("LiveSyncTest");
if (taskPage.isRunNowVisible()){
taskPage.clickRunNow();
}
Selenide.sleep(MidPoint.TIMEOUT_EXTRA_LONG_1_M);
usersPage = basicPage.listUsers();
UserProjectionsTab projectionsTab = usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.TEST_USER_DON_NAME)
.selectTabProjections();
Selenide.screenshot("SynchronizationTests_projectionTab");
boolean accountExists = projectionsTab
.table()
.containsText(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME);
Assert.assertTrue(accountExists);
}
@Test (priority = 4, dependsOnMethods = {NEW_USER_ACCOUNT_CREATED_LINKED_DEPENDENCY})
public void alreadyLinkedResourceAccountModified() throws IOException {
FileUtils.copyFile(CSV_UPDATED_SOURCE_FILE,CSV_TARGET_FILE);
Selenide.sleep(10000);
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertTrue(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.TEST_USER_DON_NAME)
.selectTabBasic()
.form()
.compareInputAttributeValue("givenName","Donato")
);
}
@Test (priority = 5, dependsOnMethods = {LINKED_USER_ACCOUNT_MODIFIED})
public void alreadyLinkedResourceAccountDeleted() throws IOException {
FileUtils.copyFile(CSV_INITIAL_SOURCE_FILE,CSV_TARGET_FILE);
Selenide.sleep(3000);
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertFalse(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.currentTableContains(ScenariosCommons.TEST_USER_DON_NAME)
);
}
@Test (priority = 6, dependsOnMethods = {RESOURCE_AND_SYNC_TASK_SETUP_DEPENDENCY})
public void resourceAccountDeleted(){
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertFalse(
usersPage
.table()
.search()
.byName()
.inputValue("raphael")
.updateSearch()
.and()
.clickByName("raphael")
.selectTabProjections()
.table()
.currentTableContains(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
);
ListResourcesPage resourcesPage = basicPage.listResources();
Assert.assertFalse(
resourcesPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.clickAccountsTab()
.clickSearchInResource()
.table()
.selectCheckboxByName("raphael")
.clickCog()
.clickDelete()
.clickYes()
.and()
.clickSearchInResource()
.table()
.currentTableContains("raphael")
);
usersPage = basicPage.listUsers();
Assert.assertFalse(
usersPage
.table()
.search()
.byName()
.inputValue("raphael")
.updateSearch()
.and()
.clickByName("raphael")
.selectTabProjections()
.table()
.currentTableContains(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
);
}
@Test(priority = 7, dependsOnMethods = {LINKED_USER_ACCOUNT_DELETED})
public void resourceAccountCreatedWhenResourceUnreachable() throws IOException {
changeResourceAttribute(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME, ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, CSV_TARGET_FILE.getAbsolutePath()+"err", false);
FileUtils.copyFile(ScenariosCommons.CSV_SOURCE_FILE,CSV_TARGET_FILE);
Selenide.sleep(3000);
ListUsersPage usersPage = basicPage.listUsers();
Assert.assertFalse(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.currentTableContains(ScenariosCommons.TEST_USER_DON_NAME)
);
changeResourceAttribute(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME, ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, CSV_TARGET_FILE.getAbsolutePath(), true);
ListTasksPage tasksPage = basicPage.listTasks();
tasksPage
.table()
.clickByName("LiveSyncTest")
.clickResume();
Selenide.sleep(3000);
usersPage = basicPage.listUsers();
Assert.assertTrue(
usersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_DON_NAME)
.updateSearch()
.and()
.currentTableContains(ScenariosCommons.TEST_USER_DON_NAME)
);
}
@Test (priority = 8, dependsOnMethods = {RESOURCE_ACCOUNT_CREATED_WHEN_UNREACHABLE})
public void resourceAccountCreatedWhenResourceUnreachableToBeLinked() throws IOException {
ListUsersPage listUsersPage= basicPage.listUsers();
Assert.assertTrue(
listUsersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_RAPHAEL_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.TEST_USER_RAPHAEL_NAME)
.selectTabProjections()
.table()
.selectCheckboxByName(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
.and()
.clickHeaderActionDropDown()
.delete()
.clickYes()
.and()
.and()
.clickSave()
.feedback()
.isSuccess()
);
changeResourceAttribute(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME , ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, CSV_TARGET_FILE.getAbsolutePath()+"err",false);
FileUtils.copyFile(ScenariosCommons.CSV_SOURCE_FILE,CSV_TARGET_FILE);
changeResourceAttribute(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME , ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, CSV_TARGET_FILE.getAbsolutePath(),true);
ListTasksPage tasksPage = basicPage.listTasks();
tasksPage
.table()
.clickByName("LiveSyncTest")
.clickResume();
Selenide.sleep(3000);
listUsersPage = basicPage.listUsers();
Assert.assertTrue(
listUsersPage
.table()
.search()
.byName()
.inputValue(ScenariosCommons.TEST_USER_RAPHAEL_NAME)
.updateSearch()
.and()
.clickByName(ScenariosCommons.TEST_USER_RAPHAEL_NAME)
.selectTabProjections()
.table()
.currentTableContains(ScenariosCommons.RESOURCE_CSV_GROUPS_AUTHORITATIVE_NAME)
);
}
}