-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebdavTest.html
More file actions
306 lines (284 loc) · 11 KB
/
Copy pathwebdavTest.html
File metadata and controls
306 lines (284 loc) · 11 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
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
<div id="testDiv"></div>
<!-- Used as HTML wiki source, so nonce is NOT required -->
<script type="text/javascript">
LABKEY.requiresExt3ClientAPI(function(){
var div = Ext.get('testDiv');
function logMsg(msg, errorMsg){
var date = new Date();
var cls = '';
if (errorMsg)
{
msg = msg + " : " + errorMsg;
cls = "labkey-error";
}
div.createChild({
tag: 'span',
html: date.format('h:i:s:u') + '\t'
});
div.createChild({
tag: 'span',
class: cls,
html: msg + '<br/>'
});
if (errorMsg)
{
div.createChild({
tag: 'span',
html: date.format('h:i:s:u') + '\tTest Complete<br>'
});
}
}
function logErr(msg, errorMsg){
logMsg(msg, errorMsg ? errorMsg : 'unknown');
}
logMsg('Test Started');
//use the current container
var fileSystem = new LABKEY.FileSystem.WebdavFileSystem();
fileSystem.on('ready', function(fileSystem){
logMsg("Filesystem ready");
doTest();
}, this);
var num = 0;
//who loves ajax...
function doTest(){
switch (num){
//create files we need. always delete first just in case a file is present from a failed test
case 0:
logMsg('Creating files and directories');
doDeleteFile('newFile2.txt', onSuccess);
break;
case 1:
createFile('newFile2.txt', onSuccess);
break;
case 2:
verifyFileExists('/', 'newFile2.txt', onSuccess);
break;
case 3:
doDeleteFile('newFolder', onSuccess);
break;
case 4:
doCreateDirectory('newFolder/', onSuccess);
break;
case 5:
verifyFileExists('/', 'newFolder/', onSuccess);
break;
case 6:
doCreateDirectory('newFolder/subFolder/', onSuccess);
break;
case 7:
createFile('/newFolder/subFolder/fileInSubfolder.txt', onSuccess);
break;
case 8:
verifyFileExists('/newFolder/subFolder', 'fileInSubfolder.txt', onSuccess);
break;
//test move
case 9:
logMsg('Testing move');
doMoveFiles('/newFolder/subFolder/fileInSubfolder.txt', '/newFolder/fileInSubfolder.txt', onSuccess);
break;
case 10:
verifyFileExists('/newFolder/', 'fileInSubfolder.txt', onSuccess);
break;
case 11:
verifyFileDoesNotExist('/newFolder/subFolder/', 'fileInSubfolder.txt', onSuccess);
break;
//test rename w/ full path
case 12:
logMsg('Testing rename w/ full path');
doRename('/newFolder/fileInSubfolder.txt', '/newFolder/renamedFile.txt', onSuccess);
break;
case 13:
verifyFileExists('/newFolder/', 'renamedFile.txt', onSuccess);
break;
case 14:
verifyFileDoesNotExist('/newFolder/', 'fileInSubfolder.txt', onSuccess);
break;
//test rename w/o full path
case 15:
logMsg('Testing rename w/o full path');
doRename('/newFolder/renamedFile.txt', 'renamedAgain.txt', onSuccess);
break;
case 16:
verifyFileExists('/newFolder/', 'renamedAgain.txt', onSuccess);
break;
case 17:
verifyFileDoesNotExist('/newFolder/', 'renamedFile.txt', onSuccess);
break;
//test get history
case 18:
logMsg('Testing get history');
getHistory('/newFolder/renamedAgain.txt', onSuccess);
break;
case 19:
verifyFileExists('/newFolder/', 'renamedAgain.txt', onSuccess);
break;
case 20:
verifyFileDoesNotExist('/newFolder/', 'renamedFile.txt', onSuccess);
break;
//cleanup
case 21:
logMsg('Starting cleanup');
doDeleteFile('newFile2.txt', onSuccess);
break;
case 22:
doDeleteFile('newFolder/' ,onSuccess);
break;
case 23:
doDeleteFile('newFolder2/' ,onSuccess);
break;
case 24:
doListFiles('/', 0, onSuccess);
break;
case 25:
logMsg('Test Complete');
break;
}
function onSuccess(msg){
if(msg)
logMsg(msg);
num++;
doTest();
}
}
function doDeleteFile(path, success){
fileSystem.deletePath({
path: path,
success: function(){
success("Deleted file: " + path);
},
failure: function(e){
logErr('ERROR: unable to delete file ' + path, e.message);
},
scope: this
}, this);
}
function doListFiles(path, expected, success){
fileSystem.listFiles({
path: path,
success: function(fileSystem, path, records){
if(records.length == expected){
success('Loaded directory with ' + records.length + ' files');
}
else
logErr('ERROR: wrong number of files found', 'Expected: ' + expected + ', Found: ' + records.length);
},
failure: function(e){
logErr('ERROR: unable to load files', e.message);
},
scope: this
}, this);
}
function doCreateDirectory(name, success){
fileSystem.createDirectory({
path: name,
success: function(){
success('Created folder: ' + name);
},
failure: function(response, options){
logErr("ERROR: unable to creating directory: " + name, response.message);
},
scope: this
});
}
function doMoveFiles(source, dest, success){
fileSystem.movePath({
source: source,
destination: dest,
isFile: true,
success: function(fileSystem, path, records){
success("Moved files from: " + source + ' to ' + dest);
},
failure: function(response, options){
logErr('ERROR: unable to perform move', response.message);
},
scope: this
});
}
function doRename(source, dest, success){
fileSystem.renamePath({
source: source,
destination: dest,
isFile: true,
success: function(fileSystem, path, records){
success("Renamed file from: " + source + ' to ' + dest);
},
failure: function(response, options){
logErr('ERROR: unable to perform rename', response.message);
},
scope: this
});
}
function getHistory(path, success){
fileSystem.getHistory({
path: path,
success: function(fileSystem, path, records){
if(records.length > 0)
success("Obtained history for: " + path);
else
logErr('ERROR: problem getting history for file', path);
},
failure: function(response, options){
logErr('ERROR getting history for file: ' + path, response.message);
},
scope: this
});
}
function createFile(name, success){
var client = new XMLHttpRequest();
client.onreadystatechange = function()
{
if (client.readyState == 4)
{
if (200 == client.status || 201 == client.status) // OK, CREATED
success("File created: " + name);
else
{
logErr('ERROR: unable to create file', "status = " + client.status);
console.log(client)
}
}
};
var resourcePath = LABKEY.ActionURL.getContextPath() + '/_webdav' + LABKEY.ActionURL.getContainer() + '/@files/' + name;
client.open("PUT", resourcePath);
client.setRequestHeader("method", "PUT");
client.setRequestHeader("Translate", "f");
client.setRequestHeader("Content-Type", "text/plain");
client.send('abcd');
}
function verifyFile(path, name, status, success)
{
var filepath = fileSystem.concatPaths(path, name);
fileSystem.listFiles({
path: path,
forceReload: true,
success: function(fileSystem, path, records){
var record = fileSystem.recordFromCache(filepath);
if(status){
if(record)
success('Verified file exists: ' + filepath);
else
logErr('ERROR: file does not exist', filepath);
}
else {
if(!record)
success('Verified file does not exist: ' + filepath);
else
logErr('ERROR: file exists', filepath);
}
},
failure: function(e){
logErr('ERROR: unable to load files: ' + path, e.message);
},
scope: this
}, this);
}
function verifyFileExists(path, name, success)
{
verifyFile(path, name, true, success);
}
function verifyFileDoesNotExist(path, name, success)
{
verifyFile(path, name, false, success)
}
});
</script>