Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Stefane Fermigier
jio
Commits
71f4dca9
Commit
71f4dca9
authored
Jun 07, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into queries
parents
921c87d1
bd7e841b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
685 additions
and
125 deletions
+685
-125
Makefile
Makefile
+4
-0
jio.js
jio.js
+1
-1
src/jio.storage/s3storage.js
src/jio.storage/s3storage.js
+10
-55
src/jio/jobs/jobRules.js
src/jio/jobs/jobRules.js
+1
-1
test/jiotests.js
test/jiotests.js
+602
-5
test/run-qunit.js
test/run-qunit.js
+67
-63
No files found.
Makefile
View file @
71f4dca9
...
...
@@ -56,6 +56,10 @@ uglify:
lint
:
$(LINT_CMD)
$(LINT_FILES)
phantom
:
~/node_modules/phantomjs/bin/phantomjs
test
/run-qunit.js
test
/jiotests_withoutrequirejs.html |
awk
'BEGIN {print "<!DOCTYPE html><html>"} /^<head>$$/, /^<\/body>$$/ {print} END {print "</html>"}'
|
sed
-e
's,^ *<\(/\|\)script.*>$$,,g'
>
test
/unit_test_result.html
grep
'^ <title>✔ '
test
/unit_test_result.html
>
/dev/null
.phony
:
clean
clean
:
find
-name
'*~'
-delete
...
...
jio.js
View file @
71f4dca9
...
...
@@ -2215,7 +2215,7 @@ var jobRules = (function () {
that
.
sameAttachmentId
],
that
.
wait
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
remove
"
,
[
that
.
sameDocumentId
,
that
.
sameRevision
],
that
.
update
);
[
that
.
sameDocumentId
,
that
.
sameRevision
],
that
.
wait
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
removeAttachment
"
,
[
that
.
sameDocument
],
that
.
update
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
removeAttachment
"
,
[
...
...
src/jio.storage/s3storage.js
View file @
71f4dca9
...
...
@@ -15,8 +15,6 @@ jIO.addStorageType("s3", function (spec, my) {
priv
.
AWSIdentifier
=
spec
.
AWSIdentifier
||
''
;
priv
.
password
=
spec
.
password
||
''
;
priv
.
server
=
spec
.
server
||
''
;
/*|| jiobucket ||*/
priv
.
url
=
spec
.
url
||
''
;
/*||> https://s3-eu-west-1.amazonaws.com <||*/
priv
.
acl
=
spec
.
acl
||
''
;
/*||> "private,
...
...
@@ -194,7 +192,6 @@ jIO.addStorageType("s3", function (spec, my) {
return
{
"
username
"
:
priv
.
username
,
"
password
"
:
priv
.
password
,
"
url
"
:
priv
.
url
,
"
server
"
:
priv
.
server
,
"
acl
"
:
priv
.
acl
};
...
...
@@ -210,9 +207,6 @@ jIO.addStorageType("s3", function (spec, my) {
if
(
typeof
priv
.
password
===
"
string
"
&&
priv
.
password
===
''
)
{
return
'
Need at least one parameter "password".
'
;
}
if
(
typeof
priv
.
url
===
"
string
"
&&
priv
.
url
===
''
)
{
return
'
Need at least one parameter "url".
'
;
}
if
(
typeof
priv
.
server
===
"
string
"
&&
priv
.
server
===
''
)
{
return
'
Need at least one parameter "server".
'
;
}
...
...
@@ -415,9 +409,7 @@ jIO.addStorageType("s3", function (spec, my) {
doc
=
JSON
.
stringify
(
doc
);
break
;
case
"
update
"
:
console
.
log
(
doc
.
_attachments
);
doc
.
_attachments
[
attachid
]
=
data
;
console
.
log
(
doc
.
_attachments
);
//update happened in the put request
doc
=
JSON
.
stringify
(
doc
);
break
;
...
...
@@ -529,7 +521,7 @@ jIO.addStorageType("s3", function (spec, my) {
**/
that
.
post
=
function
(
command
)
{
//as S3 encoding key are directly inserted within the FormData(),
//as S3 encoding key are directly inserted within the FormData(),
//use of XHRwrapper function ain't pertinent
var
doc
,
doc_id
,
mime
;
...
...
@@ -539,7 +531,7 @@ jIO.addStorageType("s3", function (spec, my) {
function
postDocument
()
{
var
http_response
,
fd
,
Signature
,
xhr
;
doc_id
=
priv
.
secureName
(
priv
.
idsToFileName
(
doc_id
));
//Meant to deep-serialize in order to avoid
//Meant to deep-serialize in order to avoid
//conflicts due to the multipart enctype
doc
=
JSON
.
stringify
(
doc
);
http_response
=
''
;
...
...
@@ -872,9 +864,12 @@ jIO.addStorageType("s3", function (spec, my) {
requestUTC
,
parse
,
checkCounter
;
keys
=
$
(
mon_document
).
find
(
'
Key
'
);
resultTable
=
[];
counter
=
0
;
keys
.
each
(
function
(
index
)
{
var
that
,
filename
,
docId
;
that
=
$
(
this
);
...
...
@@ -899,6 +894,7 @@ jIO.addStorageType("s3", function (spec, my) {
//needed to save the index within the $.ajax.success() callback
count
=
resultTable
.
length
-
1
;
countB
=
0
;
dealCallback
=
function
(
i
,
countB
,
allDoc
)
{
return
function
(
doc
,
statustext
,
response
)
{
allDoc
.
rows
[
i
].
doc
=
response
.
responseText
;
...
...
@@ -925,13 +921,16 @@ jIO.addStorageType("s3", function (spec, my) {
};
i
=
resultTable
.
length
-
1
;
if
(
command
.
getOption
(
"
include_docs
"
)
===
true
)
{
for
(
i
;
i
>=
0
;
i
-=
1
)
{
keyId
=
resultTable
[
i
];
Signature
=
that
.
encodeAuthorization
(
keyId
);
callURL
=
priv
.
url
+
keyId
;
callURL
=
'
http://
'
+
priv
.
server
+
'
.s3.amazonaws.com/
'
+
keyId
;
requestUTC
=
new
Date
().
toUTCString
();
parse
=
true
;
allDocResponse
.
rows
[
i
]
=
{
"
id
"
:
priv
.
fileNameToIds
(
keyId
).
join
(),
"
key
"
:
keyId
,
...
...
@@ -950,7 +949,6 @@ jIO.addStorageType("s3", function (spec, my) {
+
priv
.
AWSIdentifier
+
"
:
"
+
Signature
,
//'Host' : priv.url,
'
x-amz-date
'
:
requestUTC
,
'
Content-Type
'
:
'
application/json
'
//'Content-MD5' : ''
...
...
@@ -991,46 +989,3 @@ jIO.addStorageType("s3", function (spec, my) {
};
return
that
;
});
/*
// It is not possible to attach listeners to xhr level 2 events
// AND validate the Qunit tests through sinon.js
// therefore, below methods are deprecated
var S3specifics = {};
S3specifics.uploadProgress = function(evt){
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
console.log(percentComplete.toString() + '%');
} else {
console.log('Unable to compute.');
}
};
S3specifics.uploadComplete = function(evt){
var evt_txt = evt.target.responseText;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(evt_txt, "text/xml");
var responseURL = $(xmlDoc.getElementsByTagName('Location'))[0].text();
console.log(responseURL);
};
S3specifics.uploadFailed = function(evt){
var evt_txt = evt.target.responseText;
console.log("Erreur lors de la tentative d'upload : " + evt_txt);
};
S3specifics.uploadCanceled = function(evt){
console.log("Upload annulé par l'utilisateur ou le navigateur.");
};
S3specifics.onReadyStateChange = function(req, those, that) {
if (req.readyState === 4 && those.status === 200){
that.success({
ok: true,
id: command.getDocId()
});
}
};
*/
src/jio/jobs/jobRules.js
View file @
71f4dca9
...
...
@@ -326,7 +326,7 @@ var jobRules = (function () {
that
.
sameAttachmentId
],
that
.
wait
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
remove
"
,
[
that
.
sameDocumentId
,
that
.
sameRevision
],
that
.
update
);
[
that
.
sameDocumentId
,
that
.
sameRevision
],
that
.
wait
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
removeAttachment
"
,
[
that
.
sameDocument
],
that
.
update
);
that
.
addActionRule
(
"
removeAttachment
"
,
"
removeAttachment
"
,
[
...
...
test/jiotests.js
View file @
71f4dca9
...
...
@@ -695,6 +695,19 @@ test ("One document aim jobs at the same time (Wait for job(s))" , function () {
o
.
tick
(
o
,
1000
,
"
f
"
);
o
.
tick
(
o
,
"
f2
"
);
o
.
tick
(
o
,
"
f3
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
lol
"
},
"
Chaining callbacks
"
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
lol
"
,
"
_attachment
"
:
"
hu
"
},
function
(
err
,
response
)
{
if
(
err
)
{
return
;
}
o
.
jio
.
remove
({
"
_id
"
:
"
lol
"
},
o
.
f
);
});
o
.
tick
(
o
,
10000
);
o
.
jio
.
stop
();
});
...
...
@@ -6566,6 +6579,593 @@ test ("AllDocs", function () {
});
*/
module
(
"
Amazon S3 Storage
"
);
/*
Post without id
Create = POST non empty document
Post but document already exists
*/
test
(
"
Post
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com
"
});
o
.
server
=
sinon
.
fakeServer
.
create
();
//Post without ID (ID is generated by storage)
o
.
server
.
respondWith
(
"
GET
"
,
"
https://jiobucket.s3.amazonaws.com/
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
server
.
respondWith
(
"
POST
"
,
"
https://jiobucket.s3.amazonaws.com/
"
,
[
204
,
{},
"
HTML Response
"
]
);
//o.spy (o, "status", 405, "Post without id");
o
.
spy
(
o
,
"
jobstatus
"
,
"
done
"
,
"
Post without ID
"
);
o
.
jio
.
post
({},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Post with ID
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
https://jiobucket.s3.amazonaws.com/post1
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
server
.
respondWith
(
"
POST
"
,
"
https://jiobucket.s3.amazonaws.com/
"
,
[
204
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
'
ok
'
:
true
,
'
id
'
:
'
post1
'
},
"
Post with ID
"
);
o
.
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Post but document already exists (update)
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/post2
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
status
"
,
409
,
"
Post but document already exists (update)
"
);
//o.spy(o, "jobstatus", "done", "Post without ID");
o
.
jio
.
post
({
"
_id
"
:
"
post2
"
,
"
title
"
:
"
myPost2
"
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
/*
Put without id
Create = PUT non empty document
Updated the document
*/
test
(
"
Put
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
http://s3.amazonaws.com/jiobucket/put1
"
});
// put without id => id required
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
spy
(
o
,
"
status
"
,
20
,
"
Put without id
"
);
o
.
jio
.
put
({},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Put non empty document
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
PUT non empty document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
http://100%.json
"
,
"
title
"
:
"
myPut1
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Put an existing document (update)
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
PUT non empty document
"
);
o
.
jio
.
put
({
"
_id
"
:
"
http://100%.json
"
,
"
title
"
:
"
myPut1
"
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
test
(
"
PutAttachment
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com
"
});
//PutAttachment without document ID (document ID is required)
o
.
server
=
sinon
.
fakeServer
.
create
();
//PutAttachment without attachment ID (attachment ID is required)
o
.
spy
(
o
,
"
status
"
,
20
,
"
PutAttachment without doc id -> 20
"
);
o
.
jio
.
putAttachment
({
"
_attachment
"
:
"
putattmt1
"
},
o
.
f
);
o
.
tick
(
o
);
// putAttachment without attachment id => 22 Attachment Id Required
o
.
spy
(
o
,
"
status
"
,
22
,
"
PutAttachment without attachment id -> 22
"
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
http://100%.json
"
},
o
.
f
);
o
.
tick
(
o
);
//PutAttachment without underlying document (document is required)
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
PutAttachment without document -> 404
"
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
putattmt2
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//PutAttachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,{
"
Content-Type
"
:
"
text/plain
"
},
'
{"_id":"http://100%.json","title":"Hi There!"}
'
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
200
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
,
"
attachment
"
:
"
body.html
"
},
"
PutAttachment
"
);
o
.
jio
.
putAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
,
"
_mimetype
"
:
"
text/html
"
,
"
_data
"
:
"
<h1>Hi There!!</h1><p>How are you?</p>
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
/*
Get non existing document
Get non existing attachment
Get document
Get non existing attachment (doc exists)
Get attachment
*/
test
(
"
Get
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com
"
});
//Get non existing document
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
https://jiobucket.s3.amazonaws.com/doc
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing document
"
);
o
.
jio
.
get
(
"
doc
"
,
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Get document
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,{
"
Content-Type
"
:
"
text/plain
"
},
'
{"_id":"http://100%.json","title":"Hi There!"}
'
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
_id
"
:
"
http://100%.json
"
,
"
title
"
:
"
Hi There!
"
},
"
Get document
"
)
o
.
jio
.
get
({
"
_id
"
:
"
http://100%.json
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
test
(
"
GetAttachment
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com
"
});
//Get non existing attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
404
,
{},
"
HTML Response
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Get non existing attachment
"
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Get attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
My Attachment Content
"
]
);
o
.
spy
(
o
,
"
value
"
,
"
My Attachment Content
"
,
"
Get attachment
"
);
o
.
jio
.
getAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
//begins the remove tests
/*
Remove inexistent document
Remove inexistent document/attachment
Remove document
Check index file
Check if document has been removed
Remove one of multiple attachment
Check index file
Remove one document and attachment together
Check index file
Check if attachment has been removed
Check if document has been removed
*/
test
(
"
Remove
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com/
"
});
//Remove non-existing document
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
404
,
{},
"
HTML RESPONSE
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove non existing document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
restore
();
//Remove document
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
My Attachment Content
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//Remove document with multiple attachments
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
JSON
.
stringify
({
"
_attachments
"
:
{
"
body.html
"
:
{
"
length
"
:
32
,
"
digest
"
:
"
md5-dontcare
"
,
"
content_type
"
:
"
text/html
"
},
"
other
"
:
{
"
length
"
:
3
,
"
digest
"
:
"
md5-dontcare-again
"
,
"
content_type
"
:
"
text/plain
"
}
}
})
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.other
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
<h1>Deleted</h1>
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
},
"
Remove document containing multiple attachments
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
http://100%.json
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
1000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
test
(
"
RemoveAttachment
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com/
"
});
//Remove non-existing attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
404
,
{},
"
HTML RESPONSE
"
]
);
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove non existing attachment
"
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
server
.
restore
();
//Remove attachment
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,{
"
Content-Type
"
:
"
text/plain
"
},
'
{"_id":"http://100%.json","title":"Hi There!"}
'
]
);
o
.
server
.
respondWith
(
"
PUT
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json
"
,
[
200
,{
"
Content-Type
"
:
"
text/plain
"
},
'
{"_id":"http://100%.json","title":"Hi There!"}
'
]
);
o
.
server
.
respondWith
(
"
DELETE
"
,
"
http://s3.amazonaws.com/jiobucket/http:%252F%252F100%2525_.json.body_.html
"
,
[
200
,
{
"
Content-Type
"
:
"
text/plain
"
},
"
My Attachment Content
"
]
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
http://100%.json
"
,
"
attachment
"
:
"
body.html
"
},
"
Remove attachment
"
);
o
.
jio
.
removeAttachment
({
"
_id
"
:
"
http://100%.json
"
,
"
_attachment
"
:
"
body.html
"
},
{
"
max_retry
"
:
1
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
test
(
"
AllDocs
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
s3
"
,
"
AWSIdentifier
"
:
"
dontcare
"
,
"
password
"
:
"
dontcare
"
,
"
server
"
:
"
jiobucket
"
,
"
url
"
:
"
https://jiobucket.s3.amazonaws.com/
"
});
//allDocs without option
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/
"
,
[
204
,
{},
'
<?xml version="1.0" encoding="UTF-8"?><ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>jiobucket</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>documentONE</Key><LastModified>2013-05-03T15:32:01.000Z</LastModified><ETag>"8a65389818768e1f5e6530a949233581"</ETag><Size>163</Size><Owner><ID>5d09e586ab92acad85e9d053f769cce65f82178e218d9ac9b0473f3ce7f89606</ID><DisplayName>jonathan.rivalan</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>documentONE.1st_Attachment_manual</Key><LastModified>2013-05-03T15:32:02.000Z</LastModified><ETag>"f391dec65366d2b470406bc7b9595dea"</ETag><Size>35</Size><Owner><ID>5d09e586ab92acad85e9d053f769cce65f82178e218d9ac9b0473f3ce7f89606</ID><DisplayName>jonathan.rivalan</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>
'
]
);
o
.
spy
(
o
,
"
jobstatus
"
,
"
done
"
,
"
AllDocs without include docs
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
//allDocs with the include docs option
o
.
server
=
sinon
.
fakeServer
.
create
();
o
.
server
.
respondWith
(
"
GET
"
,
"
http://s3.amazonaws.com/jiobucket/
"
,
[
204
,
{},
'
<?xml version="1.0" encoding="UTF-8"?><ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>jiobucket</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>documentONE</Key><LastModified>2013-05-03T15:32:01.000Z</LastModified><ETag>"8a65389818768e1f5e6530a949233581"</ETag><Size>163</Size><Owner><ID>5d09e586ab92acad85e9d053f769cce65f82178e218d9ac9b0473f3ce7f89606</ID><DisplayName>jonathan.rivalan</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>documentONE.1st_Attachment_manual</Key><LastModified>2013-05-03T15:32:02.000Z</LastModified><ETag>"f391dec65366d2b470406bc7b9595dea"</ETag><Size>35</Size><Owner><ID>5d09e586ab92acad85e9d053f769cce65f82178e218d9ac9b0473f3ce7f89606</ID><DisplayName>jonathan.rivalan</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>
'
]
);
o
.
server
.
respondWith
(
"
GET
"
,
"
http://jiobucket.s3.amazonaws.com/documentONE
"
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
JSON
.
stringify
({
"
_attachments
"
:
{
"
body.html
"
:
{
"
length
"
:
32
,
"
digest
"
:
"
md5-dontcare
"
,
"
content_type
"
:
"
text/html
"
},
"
other
"
:
{
"
length
"
:
3
,
"
digest
"
:
"
md5-dontcare-again
"
,
"
content_type
"
:
"
text/plain
"
}
}
})
]
);
console
.
log
(
o
);
o
.
spy
(
o
,
"
jobstatus
"
,
"
done
"
,
"
AllDocs with include docs
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
console
.
log
(
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
o
.
tick
(
o
);
o
.
server
.
restore
();
o
.
jio
.
stop
();
});
var
nThen
=
function
(
next
)
{
var
funcs
=
[];
var
calls
=
0
;
...
...
@@ -6610,6 +7210,7 @@ test ("XWiki Live Server setup", function () {
var
o
=
setUp
(
this
);
o
.
jio
.
stop
();
this
.
sandbox
.
restore
();
o
.
server
.
restore
();
o
.
jio
.
start
();
QUnit
.
stop
();
...
...
@@ -6669,11 +7270,7 @@ test ("XWiki Live Server setup", function () {
// get Attachment
o
.
jio
.
getAttachment
({
"
_id
"
:
"
one.json
"
,
"
_attachment
"
:
"
att.txt
"
},
waitFor
(
function
(
err
,
ret
)
{
ok
(
!
err
);
var
fr
=
new
FileReader
();
fr
.
onload
=
waitFor
(
function
(
dat
)
{
ok
(
dat
.
target
.
result
==
"
there2
"
);
});
fr
.
readAsText
(
ret
);
ok
(
ret
==
"
there2
"
);
}));
}).
nThen
(
function
(
waitFor
)
{
...
...
test/run-qunit.js
View file @
71f4dca9
/*jslint indent: 2, maxlen: 80 */
/*global require: true, phantom: true, document: true */
"
use strict
"
;
var
system
=
require
(
'
system
'
);
/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
*
* @param testFx javascript condition that evaluates to a boolean,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param onReady what to do when testFx condition is fulfilled,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
* as a callback function.
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
* @method waitFor
* @param {Function} testFx Condition that evaluates to a boolean
* @param {Function} onReady What to do when testFx condition is fulfilled
* @param {Number} time_out_millis The max amount of time to wait.
* If not specified, 10 sec is used.
*/
function
waitFor
(
testFx
,
onReady
,
timeOutMillis
)
{
var
maxtimeOutMillis
=
timeOutMillis
?
timeOutMillis
:
3001
,
//< Default Max Timout is 3s
start
=
new
Date
().
getTime
(),
condition
=
false
,
interval
=
setInterval
(
function
()
{
if
(
(
new
Date
().
getTime
()
-
start
<
maxtimeOutMillis
)
&&
!
condition
)
{
// If not time-out yet and condition not yet fulfilled
condition
=
(
typeof
(
testFx
)
===
"
string
"
?
eval
(
testFx
)
:
testFx
());
//< defensive code
}
else
{
if
(
!
condition
)
{
// If condition still not fulfilled (timeout but condition is 'false')
console
.
log
(
"
'waitFor()' timeout
"
);
phantom
.
exit
(
1
);
}
else
{
// Condition fulfilled (timeout and/or condition is 'true')
console
.
log
(
"
'waitFor()' finished in
"
+
(
new
Date
().
getTime
()
-
start
)
+
"
ms.
"
);
typeof
(
onReady
)
===
"
string
"
?
eval
(
onReady
)
:
onReady
();
//< Do what it's supposed to do once the condition is fulfilled
clearInterval
(
interval
);
//< Stop this interval
}
}
},
100
);
//< repeat check every 250ms
};
function
waitFor
(
testFx
,
onReady
,
time_out_millis
)
{
var
maxtime_out_millis
,
start
,
condition
,
interval
;
maxtime_out_millis
=
time_out_millis
||
10001
;
start
=
new
Date
().
getTime
();
condition
=
false
;
interval
=
setInterval
(
function
()
{
if
((
new
Date
().
getTime
()
-
start
<
maxtime_out_millis
)
&&
!
condition
)
{
// If not time-out yet and condition not yet fulfilled
condition
=
testFx
();
}
else
{
if
(
!
condition
)
{
// If condition still not fulfilled (timeout but condition is 'false')
console
.
log
(
"
'waitFor()' timeout
"
);
phantom
.
exit
(
1
);
}
else
{
// Condition fulfilled (timeout and/or condition is 'true')
console
.
log
(
"
'waitFor()' finished in
"
+
(
new
Date
().
getTime
()
-
start
)
+
"
ms.
"
);
onReady
();
clearInterval
(
interval
);
//< Stop this interval
}
}
},
100
);
//< repeat check every 100ms
}
if
(
system
.
args
.
length
!==
2
)
{
console
.
log
(
'
Usage: run-qunit.js URL
'
);
phantom
.
exit
(
1
);
console
.
log
(
'
Usage: run-qunit.js URL
'
);
phantom
.
exit
(
1
);
}
var
page
=
require
(
'
webpage
'
).
create
();
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
page
.
onConsoleMessage
=
function
(
msg
)
{
console
.
log
(
msg
);
// Route "console.log()" calls from within the Page context to the main Phantom
// context (i.e. current "this")
page
.
onConsoleMessage
=
function
(
msg
)
{
console
.
log
(
msg
);
};
page
.
open
(
system
.
args
[
1
],
function
(
status
){
if
(
status
!==
"
success
"
)
{
console
.
log
(
"
Unable to access network
"
);
phantom
.
exit
(
1
);
}
else
{
waitFor
(
function
(){
return
page
.
evaluate
(
function
(){
var
el
=
document
.
getElementById
(
'
qunit-testresult
'
);
if
(
el
&&
el
.
innerText
.
match
(
'
completed
'
))
{
return
true
;
}
return
false
;
});
},
function
(){
var
failedNum
=
page
.
evaluate
(
function
(){
console
.
log
(
"
========================================================
"
)
console
.
log
(
document
.
documentElement
.
innerHTML
);
console
.
log
(
"
========================================================
"
)
var
el
=
document
.
getElementById
(
'
qunit-testresult
'
);
console
.
log
(
el
.
innerText
);
try
{
return
el
.
getElementsByClassName
(
'
failed
'
)[
0
].
innerHTML
;
}
catch
(
e
)
{
}
return
10000
;
});
phantom
.
exit
((
parseInt
(
failedNum
,
10
)
>
0
)
?
1
:
0
);
});
}
page
.
open
(
system
.
args
[
1
],
function
(
status
)
{
if
(
status
!==
"
success
"
)
{
console
.
log
(
"
Unable to access network
"
);
phantom
.
exit
(
1
);
}
waitFor
(
function
()
{
return
page
.
evaluate
(
function
()
{
var
el
=
document
.
getElementById
(
'
qunit-testresult
'
);
if
(
el
&&
el
.
innerText
.
match
(
'
completed
'
))
{
return
true
;
}
return
false
;
});
},
function
()
{
var
failedNum
=
page
.
evaluate
(
function
()
{
console
.
log
(
"
========================================================
"
);
console
.
log
(
document
.
documentElement
.
innerHTML
);
console
.
log
(
"
========================================================
"
);
var
el
=
document
.
getElementById
(
'
qunit-testresult
'
);
console
.
log
(
el
.
innerText
);
try
{
return
el
.
getElementsByClassName
(
'
failed
'
)[
0
].
innerHTML
;
}
catch
(
e
)
{
}
return
10000
;
});
phantom
.
exit
((
parseInt
(
failedNum
,
10
)
>
0
)
?
1
:
0
);
});
});
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