-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanServerTests.cs
More file actions
281 lines (234 loc) · 12 KB
/
CleanServerTests.cs
File metadata and controls
281 lines (234 loc) · 12 KB
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
using System;
using System.Linq;
using System.Threading.Tasks;
using EssSharp.Integration.Setup;
using Xunit;
using Xunit.Abstractions;
namespace EssSharp.Integration
{
/// <summary>
/// Tests collection definition with <see cref="CollectionPriorityAttribute" /> for <see cref="TestCollectionOrderer" />
/// </summary>
[CollectionDefinition(nameof(CleanServerTests), DisableParallelization = true), CollectionPriority(3)]
public class CleanServerTestsCollection : ICollectionFixture<CollectionFixture> { }
/// <summary>
/// Tests for ability to delete server objects/reset a server for subsequent testing.
/// </summary>
[Collection(nameof(CleanServerTests)), Trait("type", "clean")]
public class CleanServerTests : IntegrationTestBase
{
/// <summary />
/// <param name="output" />
public CleanServerTests( ITestOutputHelper output ) : base(output) { }
[Fact(DisplayName = "CleanServerTests - 01 - Essbase_AfterConnection_CanRemoveLocks"), Priority(01)]
public async Task Essbase_AfterConnection_CanRemoveLocks()
{
// Get an unconnected server.
var server = GetEssServer();
// Get the list of existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
{
// Get the list of existing cubes.
foreach ( var cube in await application.GetCubesAsync() )
{
// Get the list of existing locks and unlock them.
foreach ( var essLock in await cube.GetLockedObjectsAsync() )
await essLock.UnlockAsync();
// Assert that the (refreshed) list of existing locks is empty.
Assert.Empty(await cube.GetLockedObjectsAsync());
}
}
}
[Fact(DisplayName = "CleanServerTests - 02 - Essbase_AfterConnection_CanRemoveScripts"), Priority(02)]
public async Task Essbase_AfterConnection_CanRemoveScripts()
{
// Get an unconnected server.
var server = GetEssServer();
// Get the list of existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
{
// Get the list of existing cubes.
foreach ( var cube in await application.GetCubesAsync() )
{
// ASO cubes cannot carry scripts.
if ( cube.CubeType is EssCubeType.ASO )
continue;
// Get and delete all existing calc scripts.
foreach ( var script in await cube.GetScriptsAsync<IEssCalcScript>() )
await script.DeleteAsync();
// Assert that the (refreshed) list of calc scripts is empty.
Assert.Empty(await cube.GetScriptsAsync<IEssCalcScript>());
// Get and delete all existing maxl scripts.
foreach ( var script in await cube.GetScriptsAsync<IEssMaxlScript>() )
await script.DeleteAsync();
// Assert that the (refreshed) list of maxl scripts is empty.
Assert.Empty(await cube.GetScriptsAsync<IEssMaxlScript>());
// Get and delete all existing mdx scripts.
foreach ( var script in await cube.GetScriptsAsync<IEssMdxScript>() )
await script.DeleteAsync();
// Assert that the (refreshed) list of mdx scripts is empty.
Assert.Empty(await cube.GetScriptsAsync<IEssMdxScript>());
// Get and delete all existing report scripts.
foreach ( var script in await cube.GetScriptsAsync<IEssReportScript>() )
await script.DeleteAsync();
// Assert that the (refreshed) list of report scripts is empty..
Assert.Empty(await cube.GetScriptsAsync<IEssReportScript>());
}
}
}
[Fact(DisplayName = "CleanServerTests - 03 - Essbase_AfterConnection_CanRemoveDrillthroughReports"), Priority(03)]
public async Task Essbase_AfterConnection_CanRemoveDrillthroughReports()
{
// Get an unconnected server.
var server = GetEssServer();
// Get the list of existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
{
// Get the list of existing cubes.
foreach ( var cube in await application.GetCubesAsync() )
{
// ASO cubes cannot carry scripts.
if ( cube.CubeType is EssCubeType.ASO )
continue;
// TODO: Support creation of drillthrough reports,
// so that we can delete them as well. vvv
/*
// Get and delete all existing reports.
foreach ( var report in await cube.GetDrillthroughReportsAsync() )
await report.DeleteAsync();
// Assert that the (refreshed) list of reports is empty.
Assert.Empty(await cube.GetDrillthroughReportsAsync());
*/
}
}
}
[Fact(DisplayName = "CleanServerTests - 04 - Essbase_AfterConnection_CanRemoveCubes"), Priority(04)]
public async Task Essbase_AfterConnection_CanRemoveCubes()
{
// Get an unconnected server.
var server = GetEssServer();
// Get all existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
{
// Get and delete all existing cubes.
foreach ( var cube in await application.GetCubesAsync() )
await application.DeleteCubeAsync(cube.Name);
// Assert that the (refreshed) list of cubes is empty.
Assert.Empty(await application.GetCubesAsync());
}
}
[Fact(DisplayName = "CleanServerTests - 05 - Essbase_AfterConnection_CanRemoveApplications"), Priority(05)]
public async Task Essbase_AfterConnection_CanRemoveApplications()
{
// Get an unconnected server.
var server = GetEssServer();
// Get and delete all existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
await application.DeleteAsync();
// Assert that the (refreshed) list of applications is empty.
Assert.Empty(await server.GetApplicationsAsync());
}
[Fact(DisplayName = "CleanServerTests - 06 - Essbase_AfterConnection_CanRemoveUsers"), Priority(06)]
public async Task Essbase_AfterConnection_CanRemoveUsers()
{
// Get a service admin connection.
var connection = GetEssConnection();
// If the connection uses an access-token, throw a not supported exception.
if (connection is { AccessToken.Length: > 0 })
throw new NotSupportedException("EssSharp tests do not support the deletion of all cloud users ");
// Get an unconnected server.
var server = GetEssServer(connection);
// Get and delete all existing users except admin.
foreach ( var user in (await server.GetUsersAsync()).Where(u => !string.Equals(u.Name, "admin")) )
{
try
{
// Attempt to delete the user...
await user.DeleteAsync();
}
catch ( Exception e )
{
// Unless the user only partially exists, which can and does happen with persistent containers, throw.
if ( e.Message?.EndsWith("User does not exist.", StringComparison.OrdinalIgnoreCase) is not true )
throw;
try
{
// Attempt to recreate the user and then delete it as a workaround.
await user.Server.CreateUserAsync(new EssUserCreationOptions(id: user.Name, password: Guid.NewGuid().ToString("D").Substring(0, 20).TrimEnd('-'), user.Role));
await user.DeleteAsync();
}
catch
{
// Throw the original exception.
throw e;
}
}
}
// Get the full list of users.
var users = await server.GetUsersAsync();
// Assert that the (refreshed) list of users contains a single user.
Assert.Single(await server.GetUsersAsync());
// Assert that the name of the only remaining user is "admin".
Assert.Equal("admin", users.First()?.Name);
}
[Fact(DisplayName = "CleanServerTests - 07 - Essbase_AfterConnection_CanRemoveUserPermissions"), Priority(07)]
public async Task Essbase_AfterConnection_CanRemoveUserPermissions()
{
// Get a service admin connection.
var connection = GetEssConnection();
// If the connection uses an access-token, throw a not supported exception.
if (connection is { AccessToken.Length: > 0 })
throw new NotSupportedException("EssSharp tests do not support the deletion of all user permissions ");
// Get an unconnected server.
var server = GetEssServer(connection);
// Get the list of existing applications.
foreach ( var application in await server.GetApplicationsAsync() )
{
// Get the list of existing locks and unlock them.
foreach ( var essPermission in await application.GetPermissionsAsync() )
await essPermission.RemovePermissionsAsync();
// Assert that the (refreshed) list of existing locks is empty.
Assert.Empty(await application.GetPermissionsAsync());
}
}
[Fact(DisplayName = "CleanServerTests - 08 - Essbase_AfterConnection_CanRemoveGroups"), Priority(08)]
public async Task Essbase_AfterConnection_CanRemoveGroups()
{
// Get a service admin connection.
var connection = GetEssConnection();
// If the connection uses an access-token, throw a not supported exception.
if (connection is { AccessToken.Length: > 0 })
throw new NotSupportedException("EssSharp tests do not support the deletion of all cloud user groups ");
// Get an unconnected server.
var server = GetEssServer(connection);
// Get the list of existing applications.
foreach ( var group in await server.GetGroupsAsync() )
{
try
{
// Attempt to delete the group...
await group.DeleteAsync();
}
catch ( Exception e )
{
// Unless the group only partially exists, which can and does happen with persistent containers, throw.
if ( e.Message?.EndsWith("Group does not exist.", StringComparison.OrdinalIgnoreCase) is not true )
throw;
try
{
// Attempt to recreate the group and then delete it as a workaround.
await group.Server.CreateGroupAsync(name: group.Name, role: group.Role);
await group.DeleteAsync();
}
catch
{
// Throw the original exception.
throw e;
}
}
}
// Assert that the (refreshed) list of existing locks is empty.
Assert.Empty(await server.GetGroupsAsync());
}
}
}