forked from fintanmm/QuickAccessAlfresco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickAccessAlfresco.Tests.ps1
342 lines (284 loc) · 13.4 KB
/
QuickAccessAlfresco.Tests.ps1
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
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
.".\QuickAccessAlfresco.ps1"
$whoAmI = $env:UserName
$linkBaseDir = "$env:userprofile\Links"
$appData = "$env:APPDATA\QuickAccessLinks"
$url = "http://localhost:8080/alfresco/service/api/people/$whoAmI/sites/"
$convertedJSON = @{0 = @{"title" = "Benchmark"; "description" = "This site is for bench marking Alfresco"; "shortName" = "benchmark";};1 = @{"title" = "Recruitment"; "description" = "Recruitment site"; "shortName" = "Recruitment";};}
$convertedCachedJSON = @{0 = @{"title" = "Benchmark"; "description" = "This site is for bench marking Alfresco"; "shortName" = "benchmark";};1 = @{"title" = "Recruitment"; "description" = "Recruitment site"; "shortName" = "Recruitment";};2 = @{"title" = "Recruitment"; "description" = "Recruitment site"; "shortName" = "Recruitment";};3 = @{"title" = "Recruitment"; "description" = "Recruitment site"; "shortName" = "Recruitment";};4 = @{"title" = "Recruitment"; "description" = "Recruitment site"; "shortName" = "Recruitment";};}
$homeAndShared = @{0 = @{"title" = "Home"; "description" = "My Files"; "shortName" = $env:UserName;};1 = @{"title" = "Shared"; "description" = "Shared Files"; "shortName" = "Shared";};}
function setUp {
New-Item -ItemType Directory -Force -Path $appData
}
function Clean-Up($links, $fileExt = ".lnk") {
# Clean up after test
$testLink = "$env:userprofile\Links\"
foreach($link in $links) {
if ($fileExt -eq ".lnk") {
if (Test-Path "$($testLink)$($link)$($fileExt)") {
Remove-Item "$($testLink)$($link)$($fileExt)"
} else {
Write-Host "Can not find $link"
}
} else {
if (Test-Path "$($appData)\$($link)$($fileExt)") {
Remove-Item "$($appData)\$($link)$($fileExt)"
} else {
Write-Host "Can not find $link"
}
}
}
}
Describe "Create-AppData" {
It "Should create the AppData folder for QuickAccessAlfresco" {
$createAppData = Create-AppData
$doesAppDataExist = Test-Path $appData
$createAppData | Should be $doesAppDataExist
}
#Remove-Item "$($appData)"
}
Describe "CopyIcon" {
It "Should copy the icon to the user appData folder." {
$doesIconExist = Test-Path "$appData\alfresco_careers_icon.ico"
$copyIcon = CopyIcon ".\alfresco_careers_icon.ico"
$copyIcon | Should be "True"
}
It "Should not copy the icon to the user appData folder." {
$doesIconExist = Test-Path "$appData\alfresco_careers_icon.ico"
$copyIcon = CopyIcon ".\alfresco_careers_icon.ico"
$copyIcon | Should be "False"
}
Clean-Up @('*') ".ico"
}
Describe 'Build-Url' {
It "Should build the URL for connecting to Alfresco." {
Build-Url | Should -Be $url
}
It "Should build the URL for connecting to Alfresco with paramaters prepended." {
$urlWithParams = Build-Url "hello=world"
$urlWithParams | Should -Be "http://localhost:8080/alfresco/service/api/people/$whoAmI/sites/?hello=world"
}
}
Describe 'Get-ListOfSites' {
It "Should retrieve a list of sites for the currently logged in user." {
$convertedObject = (Get-Content stub\sites.json)
$sites = Get-ListOfSites -url "$url/index.json"
$sites[0].title | Should Match $convertedJSON[0].title
}
}
Describe 'Create-HomeAndSharedLinks' {
It "Should not create links for the user home and shared because of the cache." {
New-Item "$appData\5.cache" -type file
$createHomeAndShared = Create-HomeAndSharedLinks
$createHomeAndShared.Count | Should be 0
}
Clean-Up @('*') ".cache"
It "Should create links for the user home and shared." {
$createHomeAndShared = Create-HomeAndSharedLinks
$createHomeAndShared[0].Description | Should Match $homeAndShared[0].description
$createHomeAndShared[0].TargetPath | Should Be "\\localhost\Alfresco\User Homes\$whoAmI"
$createHomeAndShared[1].Description | Should Match $homeAndShared[1].description
$createHomeAndShared[1].TargetPath | Should Be "\\localhost\Alfresco\Shared"
}
Clean-Up @('*') ".cache"
}
Describe 'Create-Link' {
It "Should create Quick Access link to Alfresco." {
$createLink = Create-Link $convertedJSON[0]
$result = Test-Path "$env:userprofile\Links\Benchmark.lnk"
$createLink | Should be $result
$createLink.Description | Should Match $convertedJSON[0].description
}
It "Should not create Quick Access link to Alfresco because it exists." {
$createLink = Create-Link $convertedJSON[0]
$createLink | Should be "False"
}
It "Should not create an empty Quick Access link to Alfresco." {
$createLink = Create-Link @{}
$createLink | Should be "False"
}
Clean-Up @("Home", "Shared", "Benchmark")
It "Should pepend text to the Quick Access link to Alfresco." {
$prependedJSON = $convertedJSON[0..3]
$prependedJSON[0]["prepend"] = "Alfresco - "
$createLink = Create-Link $prependedJSON[0]
$result = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$createLink | Should Not Be "False"
$createLink.Description | Should Match $prependedJSON[0].description
}
Clean-Up @('Alfresco - Benchmark')
It "Should set an icon for the Quick Access link to Alfresco." {
$iconJSON = $convertedJSON[0..3]
$iconJSON[0]["icon"] = "$appData\alfresco_careers_icon.ico"
$createLink = Create-Link $iconJSON[0] "Sites" "True"
$result = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$createLink | Should Be $result
$createLink.Description | Should Match $iconJSON[0].description
$iconFile = $createLink.IconLocation.split(",")[0]
$iconFile | Should Be "$appData\alfresco_careers_icon.ico"
}
Clean-Up @('Alfresco - Benchmark')
# FIXME: There is a side effect here, the title is prepended to when it shouldn't be
It "Should create a ftps Quick Access link to an Alfresco site." {
$createLink = Create-Link $convertedJSON[0] "Sites" "ftps"
$result = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$createLink | Should be $result
$createLink.Description | Should Match $convertedJSON[0].description
}
Clean-Up @('Alfresco - Benchmark')
It "Should create a ftps Quick Access link to user home." {
$createLink = Create-Link $homeAndShared[0] "User Homes" "ftps"
$result = Test-Path "$env:userprofile\Links\Home.lnk"
$createLink | Should be $result
$createLink.Description | Should Match "My Files"
}
Clean-Up @('Home')
It "Should create a ftps Quick Access link to Shared." {
$createLink = Create-Link $homeAndShared[1] "shared" "ftps"
$result = Test-Path "$env:userprofile\Links\Shared.lnk"
$createLink | Should be $result
$createLink.Description | Should Match "Shared Files"
}
Clean-Up @('Shared')
It "Should create a WebDav Quick Access link to an Alfresco site." {
$createLink = Create-Link $convertedJSON[0] "Sites" "https"
$result = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$createLink | Should be $result
$createLink.Description | Should Match $convertedJSON[0].description
}
Clean-Up @('Alfresco - Benchmark')
It "Should create a WebDav Quick Access link to user home." {
$createLink = Create-Link $homeAndShared[0] "User Homes" "https"
$result = Test-Path "$env:userprofile\Links\Home.lnk"
$createLink | Should be $result
$createLink.Description | Should Match "My Files"
}
Clean-Up @('Home')
It "Should create a WebDav Quick Access link to Shared." {
$createLink = Create-Link $homeAndShared[1] "shared" "https"
$result = Test-Path "$env:userprofile\Links\Shared.lnk"
$createLink | Should be $result
$createLink.Description | Should Match "Shared Files"
}
Clean-Up @('Shared')
It "Should not create any link to Alfresco because the path is wrong." {
$createLink = Create-Link $homeAndShared[1] "wrongPath"
$createLink | Should be "False"
}
}
Describe 'Create-QuickAccessLinks' {
It "Should not create any Quick Access links to sites within Alfresco because of the cache." {
New-Item "$appData\5.cache" -type file
$createLinks = Create-QuickAccessLinks $convertedCachedJSON
$createLinks.Count | Should Be 0
}
Clean-Up @('*') ".cache"
It "Should create all Quick Access links to sites within Alfresco because of the change in cache size." {
New-Item "$appData\5.cache" -type file
$createLinks = Create-QuickAccessLinks $convertedCachedJSON
$createLinks.Count | Should Be 0
Clean-Up @('*') ".cache"
Mock CacheTimeChange {return 5}
New-Item "$appData\2.cache" -type file
$createLinks = Create-QuickAccessLinks $convertedJSON
$createLinks.Count | Should Be 2
}
Clean-Up @('*') ".cache"
Clean-Up @('Alfresco - Benchmark', "Benchmark", "Recruitment")
It "Should create all Quick Access links to sites within Alfresco" {
Mock CacheTimeChange {return 5}
$createLinks = Create-QuickAccessLinks $convertedJSON
$createLinks[0].Description | Should Match $convertedJSON[0].description
$createLinks[1].Description | Should Match $convertedJSON[1].description
}
Clean-Up @('Alfresco - Benchmark', "Benchmark", "Recruitment")
It "Should pepend text to all Quick Access links to sites within Alfresco" {
Mock CacheTimeChange {return 5}
$createLinks = Create-QuickAccessLinks $convertedJSON "Alfresco - "
$benchmark = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$benchmark | Should Not Be "False"
$createLinks[0].Description | Should Match $convertedJSON[0].description
$recruitment = Test-Path "$env:userprofile\Links\Alfresco - Recruitment.lnk"
$recruitment | Should Not Be "False"
$createLinks[1].Description | Should Match $convertedJSON[1].description
}
Clean-Up @('Alfresco - Benchmark', "Alfresco - Recruitment")
It "Should add an icon to all Quick Access links to sites within Alfresco" {
$createLinks = Create-QuickAccessLinks $convertedJSON "" "$appData\alfresco_careers_icon.ico"
$benchmark = Test-Path "$env:userprofile\Links\Alfresco - Benchmark.lnk"
$benchmark | Should Not Be "False"
$icon = $createLinks[0].IconLocation.split(",")[0]
$icon | Should be "$appData\alfresco_careers_icon.ico"
$recruitment = Test-Path "$env:userprofile\Links\Alfresco - Recruitment.lnk"
$recruitment | Should Not Be "False"
$icon = $createLinks[1].IconLocation.split(",")[0]
$icon | Should be "$appData\alfresco_careers_icon.ico"
}
Clean-Up @('Alfresco - Benchmark', "Alfresco - Recruitment")
}
Describe 'CreateCache' {
It "Should create cache if it doesn't exists." {
$createCache = CreateCache
$createCache.Count | Should be 2
}
Clean-Up @('*') ".cache"
}
Describe 'CacheExists' {
It "Should test that the cache doesn't exists." {
$cacheExists = CacheExists
$cacheExists.Count | Should be 0
}
It "Should test that the cache does exists." {
New-Item "$appData\5.cache" -type file
$cacheExists = CacheExists
$cacheExists.Name | Should be "5.cache"
}
}
Describe 'CacheInit' {
It "Should not remove the cache if cache size doesn't change." {
Mock CacheTimeChange {return 5}
$CacheInit = CacheInit
$CacheInit | Should be "False"
}
Clean-Up @('*') ".cache"
It "Should remove the cache if cache size does change." {
# Mock CacheTimeChange {return 4}
New-Item "$appData\4.cache" -type file
$CacheInit = CacheInit
$CacheInit.Name | Should Match "5.cache"
}
Clean-Up @('*') ".cache"
}
Describe 'CacheSizeChanged' {
It "Should detect if there is a change in the size of the cache." {
Mock CacheTimeChange {return 5}
New-Item "$appData\4.cache" -type file
$cacheSizeChanged = CacheSizeChanged
$cacheSizeChanged | Should Match "True"
}
Clean-Up @('*') ".cache"
It "Should detect if the cache is the same size." {
New-Item "$appData\5.cache" -type file
$cacheSizeChanged = CacheSizeChanged
$cacheSizeChanged | Should Match "False"
}
Clean-Up @('*') ".cache"
}
Describe "CacheTimeChange" {
It "Should detect if the cache has been modified in the last 10 minutes. If so do a web request." {
$lastWriteTime = @{"LastWriteTime" = [datetime]"1/2/14 00:00:00";}
$cacheTimeChange = CacheTimeChange $lastWriteTime 5
$cacheTimeChange | Should Be 5
}
It "Should detect if the cache has not been modified in the last 10 minutes. If so do not do a web request." {
$lastWriteTime = @{"LastWriteTime" = get-date;}
$cacheTimeChange = CacheTimeChange $lastWriteTime
$cacheTimeChange | Should Be 0
}
It "Should detect if no date is passed to the function. If so do not do a web request." {
$cacheTimeChange = CacheTimeChange ""
$cacheTimeChange | Should Be 0
}
}