Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
0be25721
Commit
0be25721
authored
May 02, 2012
by
Tristan Cavelier
Committed by
Sebastien Robin
May 18, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DavStorage tests completed.
DavStorage in jio.storage.js completed.
parent
b2654ba5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
474 additions
and
318 deletions
+474
-318
jiotest/debug.html
jiotest/debug.html
+11
-211
jiotest/jiotests.js
jiotest/jiotests.js
+296
-15
jiotest/unhosted/jio.storage.js
jiotest/unhosted/jio.storage.js
+167
-92
No files found.
jiotest/debug.html
View file @
0be25721
...
...
@@ -2,221 +2,21 @@
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
/>
<title>
JIO
</title>
<title>
JIO QUnit/Sinon Test
</title>
<link
rel=
"stylesheet"
href=
"qunit/qunit-1.5.0.css"
/>
</head>
<body>
<div
id=
"qunit"
></div>
<script
type=
"text/javascript"
src=
"js/jquery/jquery.js"
></script>
<script
type=
"text/javascript"
src=
"unhosted/localorcookiestorage.js"
></script>
<script
type=
"text/javascript"
src=
"unhosted/jio.js"
></script>
<script
type=
"text/javascript"
src=
"unhosted/base64.js"
></script>
<script
type=
"text/javascript"
src=
"unhosted/jio.storage.js"
></script>
<!-- <script type="text/javascript" src="unhosted/sjcl.js"></script> -->
</head>
<body>
<!-- <div id="test" class="test"><div1></div>
<div id="test" class="test"><div2></div> -->
<div
id=
"divbody"
>
<div
id=
"divmessage"
></div>
<div
id=
"divdebug"
style=
"color: grey"
></div>
<div
id=
"diverror"
style=
"color: red"
></div>
</div>
<script
type=
"text/javascript"
>
<!--
////////////////////////////////////////////////////////////////////////////////
// little functions
var
objectDump
=
function
(
o
)
{
console
.
log
(
JSON
.
stringify
(
o
));
};
var
toString
=
function
(
o
)
{
return
JSON
.
stringify
(
o
);
};
var
is_array
=
function
(
v
)
{
return
Object
.
prototype
.
toString
.
apply
(
v
)
===
'
[object Array]
'
;
};
////////////////////////////////////////////////////////////////////////////////
// Preparing jio
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
job_done
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divdebug
'
).
html
(
$
(
'
#divdebug
'
).
html
()
+
'
<br />
'
+
toString
(
o
));
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
job_fail
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#diverror
'
).
html
(
$
(
'
#diverror
'
).
html
()
+
'
<br />
'
+
toString
(
o
));
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
start_saving
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Saving ...
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
stop_saving
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Saving ended.
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
start_loading
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Loading ...
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
stop_loading
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Loading ended.
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
start_checkingNameAvailability
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Checking name
'
+
o
.
job
.
userName
+
'
...
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
stop_checkingNameAvailability
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Checking name ended:
'
+
o
.
job
.
message
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
start_gettingList
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Getting list ...
'
);
}});
$
.
jio
(
'
subscribe
'
,{
'
event
'
:
'
stop_gettingList
'
,
'
func
'
:
function
(
o
)
{
$
(
'
#divmessage
'
).
html
(
$
(
'
#divmessage
'
).
html
()
+
'
<br />
'
+
'
Getting list ended:
'
+
toString
(
o
)
);
}});
$
.
jio
({
'
storage
'
:{
'
type
'
:
'
local
'
,
'
userName
'
:
'
tristan
'
},
'
applicant
'
:{
'
ID
'
:
'
www.ungproject.org
'
}});
// $.jio({'storage':{'type':'dav','userName':'tristan','password':'test',
// 'location':'https://ca-davstorage:8080','provider':'Unknown'},
// 'applicant':{'ID':'www.ungproject.org'}});
// TODO
// doc string
// localStorage.status
$
.
jio
(
'
checkNameAvailability
'
,{
'
userName
'
:
'
toto
'
});
// $.jio('isAvailable',{'userName':'tristan'});
// $.jio('saveDocument',{'fileName':'SonNom','fileContent':'SonContenu'});
// $.jio({'fileName':'SonNom','fileContent':'SonContenu','method':'saveDocument'});
// $.jio({'fileName':'SonNom2','fileContent':'SonContenu2','method':'saveDocument'});
// $.jio('loadDocument',{'fileName':'SonNom'});
// $.jio('removeDocument',{'fileName':'SonNom'});
// $.jio('getDocumentList');
////////////////////////////////////////////////////////////////////////////////
/*
// Preparing JIO
//// Setting events reactions
JIO.subscribe('job_done', function (job) {
switch(job.method) {
case 'load':
objectDump(job);
$('#divdebug').html($('#divdebug').html() + '<br />' +
job.method + ': "' + job.fileName + '" OK!' +
' Content : "' + job.file.content + '"');
break;
case 'userNameAvailable':
objectDump(job);
$('#divdebug').html($('#divdebug').html() + '<br />' +
job.method + ': "' + job.userName + '" OK!' +
' isAvailable ? "' + job.userIsAvailable + '"' +
' message : ' + job.message);
break;
default:
objectDump(job);
$('#divdebug').html($('#divdebug').html() + '<br />' +
job.method + ': "' + job.fileName + '" OK!');
break;
}
});
JIO.subscribe('job_fail', function (job) {
$('#diverror').html($('#diverror').html() + '<br/>' +
job.method + ': "' + job.fileName + '" FAILED! ' +
job.message);
});
JIO.subscribe('start_saving', function () {
console.log ('start_saving received');
$('#divmessage').html($('#divmessage').html() + '<br/>' +
'Saving ...');
// $('#divdebug').html($('#divdebug').html() + '<br/>' +
// 'save remainingjobs: ' + o.remaining.save);
});
JIO.subscribe('stop_saving', function () {
console.log ('stop_saving received');
$('#divmessage').html($('#divmessage').html() + '<br/>' +
'Saving ended.');
});
JIO.subscribe('start_loading', function () {
console.log ('start_loading received');
$('#divmessage').html($('#divmessage').html() + '<br/>' +
'Loading ...');
});
JIO.subscribe('stop_loading', function () {
console.log ('stop_loading received');
$('#divmessage').html($('#divmessage').html() + '<br/>' +
'Loading ended.');
});
// JIO.subscribe('start_deleting', function (e,o,r) {
// console.log ('start_deleting received');
// objectDump(o);
// $('#divmessage').html($('#divmessage').html() + '<br/>' +
// 'Deleting "' + o.fileName + '"...');
// $('#divdebug').html($('#divdebug').html() + '<br/>' +
// 'delete remainingjobs: ' + r);
// });
// JIO.subscribe('stop_deleting', function (e,o) {
// console.log ('stop_deleting received');
// objectDump(o);
// $('#divmessage').html($('#divmessage').html() + '<br/>' +
// 'Deleting ended with result: ' + o.status + ', message: ' + o.message);
// });
// JIO.subscribe('start_gettinglist', function (e,o) {
// console.log ('start_deleting received');
// objectDump(o);
// $('#divmessage').html($('#divmessage').html() + '<br/>' +
// 'Getting list...');
// });
// JIO.subscribe('stop_gettinglist', function (e,o) {
// console.log ('stop_deleting received');
// objectDump(o);
// $('#divmessage').html($('#divmessage').html() + '<br/>' +
// 'Getting list ended with result: ' + o.status + ', message: ' + o.message);
// $('#divdebug').html($('#divdebug').html() + '<br/>' +
// 'getList: ' + JSON.stringify(o.list));
// });
//// events set
//// init JIO
JIO.initialize({"type":"local","userName":"tristan"},"www.ungproject.com");
//// end init
//// Let's test!
if ( !JIO.isReady() ) alert('Not ready');
else {
// JIO.userNameAvailable("tristan");
// JIO.userNameAvailable("json");
// JIO.loadDocument("SonNom");
// JIO.saveDocument("Inside the document.","SonNom");
// JIO.saveDocument("Inside the document.","SonNom");
// JIO.saveDocument("Inside the document.","SonNom2");
// JIO.getDocumentList();
// JIO.loadDocument("SonNom");
// JIO.deleteDocument("SonNom");
// JIO.deleteDocument("SonNom");
// JIO.deleteDocument("SonNom3");
// JIO.getDocumentList();
}
////////////////////////////////////////////////////////////////////////////////
/* */
//-->
<script
type=
"text/javascript"
>
var
jio
=
JIO
.
createNew
({
'
type
'
:
'
dav
'
,
'
userName
'
:
'
davremove
'
,
'
password
'
:
'
test
'
,
'
location
'
:
'
https://ca-davstorage:8080
'
},
{
'
ID
'
:
'
jiotests
'
});
jio
.
removeDocument
({
'
fileName
'
:
'
file
'
,
'
callback
'
:
function
(
r
){
alert
(
JSON
.
stringify
(
r
));}});
</script>
</body>
</html>
jiotest/jiotests.js
View file @
0be25721
...
...
@@ -168,6 +168,42 @@ test ('Document load', function () {
o
.
jio
.
stop
();
});
test
(
'
Get document list
'
,
function
()
{
// Test if LocalStorage can get a list of documents.
// We create 2 documents inside localStorage to check them.
var
o
=
{};
var
clock
=
this
.
sandbox
.
useFakeTimers
();
var
t
=
this
;
var
mytest
=
function
(
value
){
o
.
f
=
function
(
result
)
{
var
objectifyDocumentArray
=
function
(
array
)
{
var
obj
=
{};
for
(
var
k
in
array
)
{
obj
[
array
[
k
].
fileName
]
=
array
[
k
];}
return
obj
;
};
deepEqual
(
objectifyDocumentArray
(
result
.
list
),
objectifyDocumentArray
(
value
),
'
getting list
'
);
};
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
getDocumentList
({
'
callback
'
:
o
.
f
});
clock
.
tick
(
510
);
if
(
!
o
.
f
.
calledOnce
)
ok
(
false
,
'
no response / too much results
'
);
};
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
local
'
,
'
userName
'
:
'
MrListName
'
},
{
"
ID
"
:
'
jiotests
'
});
var
doc1
=
{
'
fileName
'
:
'
file
'
,
'
fileContent
'
:
'
content
'
,
'
lastModified
'
:
1
,
'
creationDate
'
:
0
};
var
doc2
=
{
'
fileName
'
:
'
memo
'
,
'
fileContent
'
:
'
test
'
,
'
lastModified
'
:
5
,
'
creationDate
'
:
2
};
LocalOrCookieStorage
.
setItem
(
'
jio/local/MrListName/jiotests/file
'
,
doc1
);
LocalOrCookieStorage
.
setItem
(
'
jio/local/MrListName/jiotests/memo
'
,
doc2
);
delete
doc1
.
fileContent
;
delete
doc2
.
fileContent
;
mytest
([
doc1
,
doc2
]);
o
.
jio
.
stop
();
});
test
(
'
Document remove
'
,
function
()
{
// Test if LocalStorage can remove documents.
// We launch a remove from localstorage and we check if the file is
...
...
@@ -234,24 +270,127 @@ test ('Check name availability', function () {
o
.
jio
.
stop
();
});
test
(
'
Document load
'
,
function
()
{
// Test if DavStorage can load documents.
var
o
=
{};
var
clock
=
this
.
sandbox
.
useFakeTimers
();
var
t
=
this
;
var
mytest
=
function
(
message
,
doc
,
errprop
,
errget
)
{
var
server
=
t
.
sandbox
.
useFakeServer
();
server
.
respondWith
(
"
PROPFIND
"
,
"
https://ca-davstorage:8080/dav/davload/jiotests/file
"
,
[
errprop
,{
'
Content-Type
'
:
'
text/xml; charset="utf-8"
'
},
'
<?xml version="1.0" encoding="utf-8"?>
'
+
'
<D:multistatus xmlns:D="DAV:">
'
+
'
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
'
+
'
<D:href>/dav/davload/jiotests/file</D:href>
'
+
'
<D:propstat>
'
+
'
<D:prop>
'
+
'
<lp1:resourcetype/>
'
+
'
<lp1:creationdate>2012-05-02T10:06:42Z</lp1:creationdate>
'
+
'
<lp1:getcontentlength>201</lp1:getcontentlength>
'
+
'
<lp1:getlastmodified>Wed, 02 May 2012 10:06:39 GMT</lp1:getlastmodified>
'
+
'
<lp1:getetag>"c9-4bf0ad7e45226"</lp1:getetag>
'
+
'
<lp2:executable>F</lp2:executable>
'
+
'
<D:supportedlock>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:exclusive/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:shared/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
</D:supportedlock>
'
+
'
<D:lockdiscovery/>
'
+
'
</D:prop>
'
+
'
<D:status>HTTP/1.1 200 OK</D:status>
'
+
'
</D:propstat>
'
+
'
</D:response>
'
+
'
</D:multistatus>
'
]);
server
.
respondWith
(
"
GET
"
,
"
https://ca-davstorage:8080/dav/davload/jiotests/file
"
,
[
errget
,{},
'
content
'
]);
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
document
,
doc
,
message
);};
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
({
'
fileName
'
:
'
file
'
,
'
callback
'
:
o
.
f
});
clock
.
tick
(
500
);
server
.
respond
();
if
(
!
o
.
f
.
calledOnce
)
ok
(
false
,
'
no response / too much results
'
);
};
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
dav
'
,
'
userName
'
:
'
davload
'
,
'
password
'
:
'
checkpwd
'
,
'
location
'
:
'
https://ca-davstorage:8080
'
},
{
'
ID
'
:
'
jiotests
'
});
// note: http errno:
// 200 OK
// 201 Created
// 204 No Content
// 207 Multi Status
// 403 Forbidden
// 404 Not Found
// load an inexistant document.
mytest
(
'
load inexistant document
'
,{},
404
,
404
);
// load a document.
mytest
(
'
load document
'
,{
'
fileName
'
:
'
file
'
,
'
fileContent
'
:
'
content
'
,
'
lastModified
'
:
1335953199000
,
'
creationDate
'
:
1335953202000
},
207
,
200
);
o
.
jio
.
stop
();
});
test
(
'
Document save
'
,
function
()
{
// Test if DavStorage can save documents.
var
o
=
{};
var
clock
=
this
.
sandbox
.
useFakeTimers
();
var
t
=
this
;
var
mytest
=
function
(
message
,
value
,
errnoput
,
errno
get
,
var
mytest
=
function
(
message
,
value
,
errnoput
,
errno
prop
,
lastmodified
,
overwrite
,
force
)
{
var
server
=
t
.
sandbox
.
useFakeServer
();
server
.
respondWith
(
// lastmodified = 7000, creationdate = 5000
"
PROPFIND
"
,
"
https://ca-davstorage:8080/dav/davsave/jiotests/file
"
,
[
errnoprop
,{
'
Content-Type
'
:
'
text/xml; charset="utf-8"
'
},
'
<?xml version="1.0" encoding="utf-8"?>
'
+
'
<D:multistatus xmlns:D="DAV:">
'
+
'
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
'
+
'
<D:href>/dav/davsave/jiotests/file</D:href>
'
+
'
<D:propstat>
'
+
'
<D:prop>
'
+
'
<lp1:resourcetype/>
'
+
'
<lp1:creationdate>Thu, 01 Jan 1970 00:00:05 GMT</lp1:creationdate>
'
+
'
<lp1:getcontentlength>7</lp1:getcontentlength>
'
+
'
<lp1:getlastmodified>Thu, 01 Jan 1970 00:00:07 GMT</lp1:getlastmodified>
'
+
'
<lp1:getetag>"c9-4bf0ad7e45226"</lp1:getetag>
'
+
'
<lp2:executable>F</lp2:executable>
'
+
'
<D:supportedlock>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:exclusive/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:shared/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
</D:supportedlock>
'
+
'
<D:lockdiscovery/>
'
+
'
</D:prop>
'
+
'
<D:status>HTTP/1.1 200 OK</D:status>
'
+
'
</D:propstat>
'
+
'
</D:response>
'
+
'
</D:multistatus>
'
]);
server
.
respondWith
(
"
PUT
"
,
"
https://ca-davstorage:8080/dav/davsave/jiotests/file
"
,
[
errnoput
,
{
'
Content-Type
'
:
'
x-www-form-urlencoded
'
},
'
content
'
]);
server
.
respondWith
(
"
MKCOL
"
,
"
https://ca-davstorage:8080/dav/davsave/jiotests/file
"
,
[
200
,
{
'
Content-Type
'
:
'
x-www-form-urlencoded
'
},
'
content
'
]);
server
.
respondWith
(
"
GET
"
,
"
https://ca-davstorage:8080/dav/davsave/jiotests/file
"
,
[
errnoget
,
{},
'
content
'
]);
server
.
respondWith
(
"
GET
"
,
"
https://ca-davstorage:8080/dav/davsave/jiotests/file
"
,
[
errnoprop
===
207
?
200
:
errnoprop
,{},
'
content
'
]);
// server.respondWith ("MKCOL","https://ca-davstorage:8080/dav",
// [200,{},'']);
// server.respondWith ("MKCOL","https://ca-davstorage:8080/dav/davsave",
// [200,{},'']);
// server.respondWith ("MKCOL",
// "https://ca-davstorage:8080/dav/davsave/jiotests",
// [200,{},'']);
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
isSaved
,
value
,
message
);};
t
.
spy
(
o
,
'
f
'
);
...
...
@@ -272,28 +411,170 @@ test ('Document save', function () {
// 200 OK
// 201 Created
// 204 No Content
// 207 Multi Status
// 403 Forbidden
// 404 Not Found
// the path does not exist, we want to create it, and save the file.
mytest
(
'
create path if not exists, and create document
'
,
true
,
403
,
404
,
999
);
//
//
the path does not exist, we want to create it, and save the file.
//
mytest('create path if not exists, and create document',
// true,201,404,9
999);
// the document does not exist, we want to create it
mytest
(
'
create document
'
,
true
,
201
,
404
,
10000
);
// the document already exists, we want to overwrite it
mytest
(
'
overwrite document
'
,
true
,
204
,
20
0
,
10100
,
true
);
true
,
204
,
20
7
,
10100
,
true
);
// the document already exists, we don't want to overwrite it
mytest
(
'
do not overwrite document
'
,
false
,
204
,
20
0
,
10200
,
false
);
false
,
204
,
20
7
,
10200
,
false
);
// the document is already exists, it is younger than the one we want
// to save.
mytest
(
'
younger than the one we want to save
'
,
false
,
204
,
20
0
,
90
0
,
true
,
false
);
false
,
204
,
20
7
,
0
,
true
,
false
);
// the document is already exists, it is the youngest but we want to
// force overwriting
mytest
(
'
youngest but force overwrite
'
,
true
,
204
,
200
,
700
,
true
,
true
);
true
,
204
,
207
,
0
,
true
,
true
);
o
.
jio
.
stop
();
});
test
(
'
Get Document List
'
,
function
()
{
// Test if DavStorage can get a list a document.
var
o
=
{};
var
clock
=
this
.
sandbox
.
useFakeTimers
();
var
t
=
this
;
var
mytest
=
function
(
message
,
value
,
errnoprop
)
{
var
server
=
t
.
sandbox
.
useFakeServer
();
server
.
respondWith
(
"
PROPFIND
"
,
"
https://ca-davstorage:8080/dav/davlist/jiotests/
"
,
[
errnoprop
,{
'
Content-Type
'
:
'
text/xml; charset="utf-8"
'
},
'
<?xml version="1.0" encoding="utf-8"?>
'
+
'
<D:multistatus xmlns:D="DAV:">
'
+
'
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
'
+
'
<D:href>/dav/davgetlist/jiotests/</D:href>
'
+
'
<D:propstat>
'
+
'
<D:prop>
'
+
'
<lp1:resourcetype><D:collection/></lp1:resourcetype>
'
+
'
<lp1:creationdate>2012-05-02T12:48:33Z</lp1:creationdate>
'
+
'
<lp1:getlastmodified>Wed, 02 May 2012 12:48:33 GMT</lp1:getlastmodified>
'
+
'
<lp1:getetag>"1000-4bf0d1aeb9e43"</lp1:getetag>
'
+
'
<D:supportedlock>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:exclusive/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:shared/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
</D:supportedlock>
'
+
'
<D:lockdiscovery/>
'
+
'
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
'
+
'
</D:prop>
'
+
'
<D:status>HTTP/1.1 200 OK</D:status>
'
+
'
</D:propstat>
'
+
'
</D:response>
'
+
'
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
'
+
'
<D:href>/dav/davgetlist/jiotests/file</D:href>
'
+
'
<D:propstat>
'
+
'
<D:prop>
'
+
'
<lp1:resourcetype/>
'
+
'
<lp1:creationdate>2012-05-02T12:48:31Z</lp1:creationdate>
'
+
'
<lp1:getcontentlength>201</lp1:getcontentlength>
'
+
'
<lp1:getlastmodified>Wed, 02 May 2012 12:48:27 GMT</lp1:getlastmodified>
'
+
'
<lp1:getetag>"c9-4bf0d1a845df9"</lp1:getetag>
'
+
'
<lp2:executable>F</lp2:executable>
'
+
'
<D:supportedlock>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:exclusive/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:shared/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
</D:supportedlock>
'
+
'
<D:lockdiscovery/>
'
+
'
</D:prop>
'
+
'
<D:status>HTTP/1.1 200 OK</D:status>
'
+
'
</D:propstat>
'
+
'
</D:response>
'
+
'
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
'
+
'
<D:href>/dav/davgetlist/jiotests/memo</D:href>
'
+
'
<D:propstat>
'
+
'
<D:prop>
'
+
'
<lp1:resourcetype/>
'
+
'
<lp1:creationdate>2012-05-01T17:41:13Z</lp1:creationdate>
'
+
'
<lp1:getcontentlength>223</lp1:getcontentlength>
'
+
'
<lp1:getlastmodified>Wed, 02 May 2012 10:48:33 GMT</lp1:getlastmodified>
'
+
'
<lp1:getetag>"c9-4bf0d1aeb9e43"</lp1:getetag>
'
+
'
<lp2:executable>F</lp2:executable>
'
+
'
<D:supportedlock>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:exclusive/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
<D:lockentry>
'
+
'
<D:lockscope><D:shared/></D:lockscope>
'
+
'
<D:locktype><D:write/></D:locktype>
'
+
'
</D:lockentry>
'
+
'
</D:supportedlock>
'
+
'
<D:lockdiscovery/>
'
+
'
</D:prop>
'
+
'
<D:status>HTTP/1.1 200 OK</D:status>
'
+
'
</D:propstat>
'
+
'
</D:response>
'
+
'
</D:multistatus>
'
]);
o
.
f
=
function
(
result
)
{
var
objectifyDocumentArray
=
function
(
array
)
{
var
obj
=
{};
for
(
var
k
in
array
)
{
obj
[
array
[
k
].
fileName
]
=
array
[
k
];}
return
obj
;
};
deepEqual
(
objectifyDocumentArray
(
result
.
list
),
objectifyDocumentArray
(
value
),
message
);
};
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
getDocumentList
({
'
callback
'
:
o
.
f
});
clock
.
tick
(
500
);
server
.
respond
();
if
(
!
o
.
f
.
calledOnce
)
ok
(
false
,
'
no response / too much results
'
);
};
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
dav
'
,
'
userName
'
:
'
davlist
'
,
'
password
'
:
'
checkpwd
'
,
'
location
'
:
'
https://ca-davstorage:8080
'
},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
fail to get list
'
,
undefined
,
404
);
mytest
(
'
getting list
'
,[{
'
fileName
'
:
'
file
'
,
'
creationDate
'
:
1335962911000
,
'
lastModified
'
:
1335962907000
},
{
'
fileName
'
:
'
memo
'
,
'
creationDate
'
:
1335894073000
,
'
lastModified
'
:
1335955713000
}],
207
);
o
.
jio
.
stop
();
});
test
(
'
Remove document
'
,
function
()
{
// Test if DavStorage can remove documents.
var
o
=
{};
var
clock
=
this
.
sandbox
.
useFakeTimers
();
var
t
=
this
;
var
mytest
=
function
(
message
,
value
,
errnodel
)
{
var
server
=
t
.
sandbox
.
useFakeServer
();
server
.
respondWith
(
"
DELETE
"
,
"
https://ca-davstorage:8080/dav/davremove/jiotests/file
"
,
[
errnodel
,{},
''
]);
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
isRemoved
,
value
,
message
);};
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
removeDocument
({
'
fileName
'
:
'
file
'
,
'
callback
'
:
o
.
f
});
clock
.
tick
(
500
);
server
.
respond
();
if
(
!
o
.
f
.
calledOnce
)
ok
(
false
,
'
no response / too much results
'
);
};
o
.
jio
=
JIO
.
createNew
({
'
type
'
:
'
dav
'
,
'
userName
'
:
'
davremove
'
,
'
password
'
:
'
checkpwd
'
,
'
location
'
:
'
https://ca-davstorage:8080
'
},
{
'
ID
'
:
'
jiotests
'
});
mytest
(
'
remove document
'
,
true
,
204
)
mytest
(
'
remove an already removed document
'
,
true
,
404
)
o
.
jio
.
stop
();
});
jiotest/unhosted/jio.storage.js
View file @
0be25721
...
...
@@ -113,8 +113,8 @@
// date problem!
// return
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Modification date is earlier than
'
+
'
existing modification dat
e.
'
;
res
.
message
=
'
Document is older than the
'
+
'
existing on
e.
'
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
...
...
@@ -280,30 +280,58 @@
// options.location : the davstorage locations
// options.path: if path=/foo/bar then creates location/dav/foo/bar
// options.success: the function called if success
// options.userName: the username
// options.password: the password
// TODO this method is not working !!!
var
settings
=
$
.
extend
({
'
success
'
:
function
(){},
'
error
'
:
function
(){}},
options
);
$
.
ajax
(
{
url
:
options
.
location
+
'
/dav/
'
+
options
.
path
,
type
:
'
MKCOL
'
,
async
:
true
,
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
()
{
// done
settings
.
success
();
},
error
:
function
(
type
)
{
switch
(
type
.
status
)
{
case
405
:
// Method Not Allowed
// already exists
settings
.
success
();
break
;
default
:
settings
.
error
();
break
;
}
// if pathstep is not defined, then split the settings.path
// and do mkcol recursively
if
(
!
settings
.
pathsteps
)
{
settings
.
pathsteps
=
1
;
this
.
mkcol
(
settings
);
}
else
{
var
splitpath
=
settings
.
path
.
split
(
'
/
'
);
// // check if the path is terminated by '/'
// if (splitpath[splitpath.length-1] == '') {
// splitpath.length --;
// }
// check if the pathstep is lower than the longer
if
(
settings
.
pathsteps
>=
splitpath
.
length
-
1
)
{
return
settings
.
success
();
}
}
);
splitpath
.
length
=
settings
.
pathsteps
+
1
;
settings
.
pathsteps
++
;
var
tmppath
=
splitpath
.
join
(
'
/
'
);
alert
(
settings
.
location
+
tmppath
);
var
t
=
this
;
$
.
ajax
(
{
url
:
settings
.
location
+
tmppath
,
type
:
'
MKCOL
'
,
async
:
true
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
settings
.
userName
+
'
:
'
+
settings
.
password
),
Depth
:
'
1
'
},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
()
{
// done
t
.
mkcol
(
settings
);
},
error
:
function
(
type
)
{
alert
(
JSON
.
stringify
(
type
));
switch
(
type
.
status
)
{
// case 405: // Method Not Allowed
// // already exists
// t.mkcol(settings);
// break;
default
:
settings
.
error
();
break
;
}
}
}
);
}
},
checkNameAvailability
:
function
(
job
,
jobendcallback
)
{
// checks the availability of the [job.userName].
...
...
@@ -367,7 +395,7 @@
var
settings
=
$
.
extend
({
'
overwrite
'
:
true
,
'
force
'
:
false
},
job
.
options
);
var
res
=
{};
// TODO if path of
../dav/user/applic does not exists, it won't work !
!
// TODO if path of
/dav/user/applic does not exists, it won't work
!
var
saveOnDav
=
function
()
{
//// save on dav
$
.
ajax
(
{
...
...
@@ -404,67 +432,71 @@
if
(
settings
.
force
)
{
return
saveOnDav
();
}
var
mkcol
=
this
.
mkcol
;
//// start loading document
$
.
ajax
(
{
url
:
job
.
storage
.
location
+
'
/dav/
'
+
job
.
storage
.
userName
+
'
/
'
+
job
.
applicant
.
ID
+
'
/
'
+
job
.
fileName
,
type
:
'
GET
'
,
async
:
true
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
job
.
storage
.
userName
+
'
:
'
+
job
.
storage
.
password
)},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
()
{
//// start loading document
var
t
=
this
;
var
tmpjob
=
$
.
extend
({},
job
);
tmpjob
.
callback
=
function
(
result
)
{
if
(
result
.
status
===
'
fail
'
)
{
switch
(
result
.
errno
)
{
case
404
:
// Document not found
// TODO MKCOL
// // we can save on it
// t.mkcol({ // create col if not exist
// userName:job.storage.userName,
// password:job.storage.password,
// location:job.storage.location,
// path:'/dav/'+job.storage.userName+'/'+
// job.applicant.ID,
// success:function(){
// // and finaly save document
// saveOnDav()
// },
// error:function(){
// res.status = job.status = 'fail';
// res.message = 'Cannot create document.';
// res.errno = type.status;
// res.isSaved = false;
// jobendcallback(job);
// job.callback(res);
// }});
saveOnDav
();
break
;
default
:
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Unknown error.
'
;
res
.
errno
=
type
.
status
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
break
;
}
}
else
{
// done
// TODO merge files
// Document already exists
if
(
settings
.
overwrite
)
{
// overwrite
// TODO check date !!!
// response headers contains
// Date: Mon, 30 Apr 2012 15:17:21 GMT
// Last-Modified: Mon, 30 Apr 2012 15:06:59 GMT
if
(
result
.
document
.
lastModified
>=
job
.
lastModified
)
{
// date ploblem !
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Document is older than the
'
+
'
existing one.
'
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
return
;
}
return
saveOnDav
();
}
// do not overwrite
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Document already exists.
'
;
res
.
errno
=
302
;
res
.
errno
=
403
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
},
error
:
function
(
type
)
{
switch
(
type
.
status
)
{
case
404
:
// Document not found
// we can save on it
mkcol
({
// create col if not exist
location
:
job
.
storage
.
location
,
path
:
'
/dav/
'
+
job
.
storage
.
userName
+
job
.
applicant
.
ID
,
success
:
function
(){
// and finaly save document
saveOnDav
()
},
error
:
function
(){
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Cannot create document.
'
;
res
.
errno
=
type
.
status
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
}});
break
;
default
:
// Unknown error
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Unknown error.
'
;
res
.
errno
=
type
.
status
;
res
.
isSaved
=
false
;
jobendcallback
(
job
);
job
.
callback
(
res
);
break
;
}
}
}
);
};
this
.
loadDocument
(
tmpjob
,
function
(){});
//// end loading document
},
loadDocument
:
function
(
job
,
jobendcallback
)
{
...
...
@@ -477,36 +509,71 @@
// returns {'status':string,'message':string,'document':object}
// in the jobendcallback arguments.
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
//TODO!!
// 'creationDate':date,'lastModified':date}
// TODO check if job's features are good
var
res
=
{};
res
.
document
=
{};
var
getContent
=
function
()
{
$
.
ajax
(
{
url
:
job
.
storage
.
location
+
'
/dav/
'
+
job
.
storage
.
userName
+
'
/
'
+
job
.
applicant
.
ID
+
'
/
'
+
job
.
fileName
,
type
:
"
GET
"
,
async
:
true
,
dataType
:
'
text
'
,
// TODO is it necessary ?
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
job
.
storage
.
userName
+
'
:
'
+
job
.
storage
.
password
)},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
content
)
{
res
.
status
=
job
.
status
=
'
done
'
;
res
.
message
=
'
Document loaded.
'
;
res
.
document
.
fileContent
=
content
;
jobendcallback
(
job
);
job
.
callback
(
res
);
},
error
:
function
(
type
)
{
switch
(
type
.
status
)
{
case
404
:
res
.
message
=
'
Document not found.
'
;
break
;
default
:
res
.
message
=
'
Cannot load "
'
+
job
.
fileName
+
'
".
'
;
break
;
}
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
errno
=
type
.
status
;
jobendcallback
(
job
);
job
.
callback
(
res
);
}
}
);
}
// Get properties
$
.
ajax
(
{
url
:
job
.
storage
.
location
+
'
/dav/
'
+
job
.
storage
.
userName
+
'
/
'
+
job
.
applicant
.
ID
+
'
/
'
+
job
.
fileName
,
type
:
"
GET
"
,
type
:
"
PROPFIND
"
,
async
:
true
,
dataType
:
'
text
'
,
// TODO is it necessary ?
dataType
:
'
xml
'
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
job
.
storage
.
userName
+
'
:
'
+
job
.
storage
.
password
)},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
content
)
{
res
.
status
=
job
.
status
=
'
done
'
;
res
.
message
=
'
Document loaded.
'
;
res
.
fileContent
=
content
;
jobendcallback
(
job
);
job
.
callback
(
res
);
success
:
function
(
xmlData
)
{
res
.
document
.
lastModified
=
(
new
Date
(
$
(
$
(
"
lp1
\\
:getlastmodified
"
,
xmlData
).
get
(
0
)).
text
())).
getTime
();
res
.
document
.
creationDate
=
(
new
Date
(
$
(
$
(
"
lp1
\\
:creationdate
"
,
xmlData
).
get
(
0
)).
text
())).
getTime
();
res
.
document
.
fileName
=
job
.
fileName
;
getContent
();
},
error
:
function
(
type
)
{
switch
(
type
.
status
)
{
case
404
:
res
.
message
=
'
Document not found.
'
;
break
;
default
:
res
.
message
=
'
Cannot load "
'
+
job
.
fileName
+
'
".
'
;
break
;
}
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Cannot get document informations.
'
;
res
.
errno
=
type
.
status
;
jobendcallback
(
job
);
job
.
callback
(
res
);
...
...
@@ -535,6 +602,7 @@
job
.
storage
.
userName
+
'
:
'
+
job
.
storage
.
password
),
Depth
:
'
1
'
},
success
:
function
(
xmlData
)
{
var
res
=
{};
var
documentArrayList
=
[];
$
(
"
D
\\
:response
"
,
xmlData
).
each
(
function
(
i
,
data
)
{
if
(
i
>
0
)
{
// exclude parent folder
...
...
@@ -547,10 +615,12 @@
if
(
file
.
fileName
===
'
.htaccess
'
||
file
.
fileName
===
'
.htpasswd
'
)
return
;
file
.
lastModified
=
$
(
$
(
"
lp1
\\
:getlastmodified
"
,
xmlData
).
get
(
i
)).
text
();
file
.
creationDate
=
$
(
$
(
"
lp1
\\
:creationdate
"
,
xmlData
).
get
(
i
)).
text
();
file
.
lastModified
=
(
new
Date
(
$
(
$
(
"
lp1
\\
:getlastmodified
"
,
xmlData
).
get
(
i
)).
text
())).
getTime
();
file
.
creationDate
=
(
new
Date
(
$
(
$
(
"
lp1
\\
:creationdate
"
,
xmlData
).
get
(
i
)).
text
())).
getTime
();
documentArrayList
.
push
(
file
);
}
});
...
...
@@ -561,6 +631,7 @@
job
.
callback
(
res
);
},
error
:
function
(
type
)
{
var
res
=
{};
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Cannot get list.
'
;
res
.
errno
=
type
.
status
;
...
...
@@ -589,6 +660,7 @@
job
.
storage
.
password
)},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
()
{
var
res
=
{};
res
.
status
=
job
.
status
=
'
done
'
;
res
.
message
=
'
Document removed.
'
;
res
.
isRemoved
=
true
;
...
...
@@ -596,15 +668,18 @@
job
.
callback
(
res
);
},
error
:
function
(
type
)
{
var
res
=
{};
switch
(
type
.
status
)
{
case
404
:
res
.
stauts
=
job
.
status
=
'
done
'
;
res
.
message
=
'
Document already removed.
'
;
res
.
errno
=
type
.
status
;
res
.
isRemoved
=
true
;
break
;
default
:
res
.
status
=
job
.
status
=
'
fail
'
;
res
.
message
=
'
Cannot remove "
'
+
job
.
fileName
+
'
".
'
;
res
.
isRemoved
=
false
;
res
.
errno
=
type
.
status
;
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment