Commit 979fca4a authored by Tristan Cavelier's avatar Tristan Cavelier

Jio can now restore older jio instance.

parent 3d2ae5e9
......@@ -15,12 +15,12 @@ module.exports = function(grunt) {
dist: {
src: ['<banner:meta.banner>',
// Wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.top.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/exceptions.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storageHandler.js>',
// Jio wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/jio.top.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jio.intro.js>',
// Jio Classes
'<file_strip_banner:../../src/<%= pkg.name %>/commands/command.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/getDocumentList.js>',
......@@ -42,10 +42,10 @@ module.exports = function(grunt) {
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobManager.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobRules.js>',
// Jio wrappor bottem
'<file_strip_banner:../../src/<%= pkg.name %>/jio.bottom.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jio.outro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jioNamespace.js>',
// Wrapper bottom
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.bottom.js>'],
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js'
}
},
......@@ -87,10 +87,7 @@ module.exports = function(grunt) {
browser: true
},
globals: {
jQuery: true,
sjcl:true,
LocalOrCookieStorage: true,
Base64: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with requireJs
......@@ -112,6 +109,6 @@ module.exports = function(grunt) {
});
// Default task.
grunt.registerTask('default', 'concat min lint qunit');
grunt.registerTask('default', 'concat lint min qunit');
};
......@@ -14,7 +14,9 @@ module.exports = function(grunt) {
concat: {
dist: {
src: ['<banner:meta.banner>',
'<file_strip_banner:../../src/<%= pkg.name %>.js>'],
'<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/localStorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js'
}
},
......@@ -28,7 +30,7 @@ module.exports = function(grunt) {
files: []
},
lint: {
files: ['grunt.js','../../src/<%= pkg.name %>.js']
files: ['grunt.js','../../lib/jio/<%= pkg.name %>.js']
},
watch: {
files: '<config:lint.files>',
......@@ -53,7 +55,7 @@ module.exports = function(grunt) {
sjcl: true,
LocalOrCookieStorage: true,
Base64: true,
JIO: true,
jio: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with requireJs
......@@ -75,6 +77,6 @@ module.exports = function(grunt) {
});
// Default task.
grunt.registerTask('default', 'lint concat min');
grunt.registerTask('default', 'concat lint min');
};
......@@ -2,11 +2,9 @@
for node in `ls -1` ; do
if [ -d "$node" ] ; then
cd "$node"
printf "\n\033[1m\033[36mgrunt --force -> %s\033[0m\n" "$node"
grunt --force
printf "\n\033[1m\033[36mmake -C %s\033[0m\n" "$node"
make -C "$node"
cd ..
fi
done
/*! JIO - v0.1.0 - 2012-06-12
/*! JIO - v0.1.0 - 2012-06-13
* Copyright (c) 2012 Nexedi; Licensed */
var jio = (function () {
......@@ -91,6 +91,7 @@ var storage = function(spec, my) {
* @param {object} command The command
*/
that.execute = function(command) {
that.validate(command);
command.executeOn(that);
};
......@@ -104,6 +105,10 @@ var storage = function(spec, my) {
};
that.validate = function(command) {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
}
command.validate(that);
};
......@@ -129,6 +134,10 @@ var storage = function(spec, my) {
that.saveDocument();
};
that.validateState = function() {
return '';
};
return that;
};
......@@ -146,24 +155,22 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method beforeExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.beforeExecute = function(command,option) {};
that.beforeExecute = function(command) {};
/**
* Execute the command according to this storage.
* @method execute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.execute = function(command,option) {
that.execute = function(command) {
var i;
that.validate(command);
that.beforeExecute(command,option);
that.beforeExecute(command);
for(i = 0; i < priv.storage_a.length; i++) {
priv.storage_a[i].execute(command);
}
that.afterExecute(command,option);
that.afterExecute(command);
};
/**
......@@ -171,10 +178,9 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method afterExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.afterExecute = function(command,option) {
that.done();
that.afterExecute = function(command) {
command.done();
};
/**
......@@ -298,7 +304,6 @@ var command = function(spec, my) {
};
that.done = function(return_value) {
console.log ('done');
priv.done(return_value);
priv.respond({status:doneStatus(),value:return_value});
priv.end();
......@@ -308,7 +313,6 @@ var command = function(spec, my) {
if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) {
priv.retry();
} else {
console.log ('fail');
priv.fail(return_error);
priv.respond({status:failStatus(),error:return_error});
priv.end();
......@@ -337,6 +341,10 @@ var command = function(spec, my) {
option:priv.option};
};
that.canBeRestored = function() {
return true;
};
return that;
};
......@@ -354,6 +362,10 @@ var getDocumentList = function(spec, my) {
storage.getDocumentList(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -371,6 +383,10 @@ var loadDocument = function(spec, my) {
storage.loadDocument(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -396,14 +412,15 @@ var saveDocument = function(spec, my) {
spec = spec || {};
my = my || {};
// Attributes //
var content = spec.content;
var priv = {};
priv.content = spec.content;
// Methods //
that.getLabel = function() {
return 'saveDocument';
};
that.getContent = function() {
return content;
return priv.content;
};
/**
......@@ -412,7 +429,7 @@ var saveDocument = function(spec, my) {
*/
var super_validate = that.validate;
that.validate = function(handler) {
if (typeof content !== 'string') {
if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'});
}
super_validate(handler);
......@@ -422,6 +439,13 @@ var saveDocument = function(spec, my) {
storage.saveDocument(that);
};
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
};
return that;
};
......@@ -568,7 +592,6 @@ var waitStatus = function(spec, my) {
that.canStart = function() {
priv.refreshJobIdArray();
console.log (priv.job_id_a);
return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold);
};
that.canRestart = function() {
......@@ -708,7 +731,6 @@ var job = function(spec, my) {
* @param {object} job The other job.
*/
that.update = function(job) {
console.log ('updating');
priv.command.setMaxRetry(-1);
priv.command.fail({status:0,statusText:'Replaced',
message:'Job has been replaced by another one.'});
......@@ -821,6 +843,8 @@ var activityUpdater = (function(spec, my) {
};
return that;
}());
var announcer = (function(spec, my) {
var that = {};
spec = spec || {};
......@@ -965,6 +989,7 @@ var jobManager = (function(spec, my) {
if (jio_date < Date.now() - 10000) {
priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
}
};
......@@ -972,9 +997,12 @@ var jobManager = (function(spec, my) {
var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) {
var command_o = command(jio_job_array[i].command);
if (command_o.canBeRestored()) {
that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i]),
command:command(jio_job_array[i].command)}));
{storage:jioNamespace.storage(jio_job_array[i].storage),
command:command_o}));
}
}
};
......@@ -987,6 +1015,11 @@ var jobManager = (function(spec, my) {
}
}
LocalOrCookieStorage.setItem('jio/id_array',new_a);
LocalOrCookieStorage.deleteItem('jio/id/'+id);
};
priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id);
};
/**
......@@ -1011,11 +1044,9 @@ var jobManager = (function(spec, my) {
var i;
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() === id) {
console.log ('found');
return true;
}
}
console.log ('not found');
return false;
};
......@@ -1047,11 +1078,9 @@ var jobManager = (function(spec, my) {
return;
}
}
console.log ('managing '+JSON.stringify (result_a));
for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) {
case 'eliminate':
console.log ('eliminating');
that.eliminate(result_a[i].job);
break;
case 'update':
......@@ -1059,7 +1088,6 @@ var jobManager = (function(spec, my) {
priv.copyJobArrayToLocal();
return;
case 'wait':
console.log ('wait');
job.waitForJob(result_a[i].job);
break;
default: break;
......@@ -1074,7 +1102,6 @@ var jobManager = (function(spec, my) {
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() !== job.getId()) {
tmp_a.push(priv.job_a[i]);
console.log ('add: '+priv.job_a[i].getId()+' -> it is not '+job.getId());
}
}
priv.job_a = tmp_a;
......@@ -1224,30 +1251,22 @@ var jobRules = (function(spec, my) {
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
try {
console.log (j1label);
console.log (j2label);
console.log (j1status);
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} catch (e) {
if(e.name==='TypeError') {
return priv.default_action(job1,job2);
} else {
throw e;
}
return priv.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
try {
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} catch(e) {
if (e.name==='TypeError') {
return priv.default_compare(job1,job2);
} else {
throw e;
}
return priv.default_compare(job1,job2);
}
};
that.validateJobAccordingToJob = function(job1,job2) {
......@@ -1267,14 +1286,16 @@ var jobRules = (function(spec, my) {
// Attributes //
var priv = {};
var jio_id_array_name = 'jio/id_array';
priv.id = 1;
priv.storage = jioNamespace.storage(spec, that);
priv.id = null;
priv.storage = jioNamespace.storage(spec);
// initialize //
(function () {
priv.init = function() {
// Initialize the jio id and add the new id to the list
var i,
jio_id_a = LocalOrCookieStorage.getItem (jio_id_array_name) || [];
if (priv.id === null) {
var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || [];
priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1;
......@@ -1282,22 +1303,26 @@ var jobRules = (function(spec, my) {
}
jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
}());
(function (){
// Start Jio updater, and the jobManager
activityUpdater.setId(priv.id);
activityUpdater.start();
jobManager.setId(priv.id);
jobManager.start();
}());
}
};
// Methods //
that.start = function() {
priv.init();
activityUpdater.start();
jobManager.start();
};
that.stop = function() {
jobManager.stop();
};
that.close = function() {
activityUpdater.stop();
jobManager.stop();
priv.id = null;
};
that.start();
/**
* Returns the jio id.
......@@ -1446,11 +1471,12 @@ var jioNamespace = (function(spec, my) {
* @method storage
* @param {object} spec The specifications.
* @param {object} my The protected object.
* @param {string} forcetype Force storage type
* @return {object} The storage object.
*/
that.storage = function(spec, my) {
that.storage = function(spec, my, forcetype) {
spec = spec || {};
var type = spec.type || 'base';
var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) {
throw invalidStorageType({type:type,
message:'Storage does not exists.'});
......
/*! JIO - v0.1.0 - 2012-06-12
/*! JIO - v0.1.0 - 2012-06-13
* Copyright (c) 2012 Nexedi; Licensed */
var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var d={};a=a||{},b=b||{};var e={};return e.type=a.type||"",d.getType=function(){return e.type},d.setType=function(a){e.type=a},d.execute=function(a){a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throw c({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d},i=function(a,b){var c=h(a,b);a=a||{},b=b||{};var d={};return d.storage_a=a.storagelist||[],c.beforeExecute=function(a,b){},c.execute=function(a,b){var e;c.validate(a),c.beforeExecute(a,b);for(e=0;e<d.storage_a.length;e++)d.storage_a[e].execute(a);c.afterExecute(a,b)},c.afterExecute=function(a,b){c.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){var d=function(a,c){var d={};a=a||{},c=c||{};var e={};return e.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,delete a.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){return e.path},d.getOption=function(a){return e.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){return e.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throw b({command:d,message:"Path is empty"})},d.done=function(a){console.log("done"),e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(console.log("fail"),e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d)},h=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c},i=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c},j=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){var e=d(a,c);a=a||{},c=c||{};var f=a.content;e.getLabel=function(){return"saveDocument"},e.getContent=function(){return f};var g=e.validate;return e.validate=function(a){if(typeof f!="string")throw b({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)},e},m=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){var c=m(a,b);a=a||{},b=b||{};var d={};return d.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),console.log(d.job_id_a),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=new Date,function(){if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"})}(),c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return d.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){console.log("updating"),d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"";return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),x=function(a,b){var c={};a=a||{},b=b||{};var e="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){return e+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a))},f.restoreOldJobFromJioId=function(a){var b,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1)c.addJob(s({storage:k.storage(e[b]),command:d(e[b].command)}))},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)return console.log("found"),!0;return console.log("not found"),!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));return d},f.manage=function(a,b){var d;if(f.job_a.length!==b.length)throw new RangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;console.log("managing "+JSON.stringify(b));for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":console.log("eliminating"),c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":console.log("wait"),a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&(c.push(f.job_a[b]),console.log("add: "+f.job_a[b].getId()+" -> it is not "+a.getId()));f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){var c={},d={};return c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){return a.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){return a.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){var c,e,f;c=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going";try{return console.log(c),console.log(e),console.log(f),d.action[c][f][e](a,b)}catch(g){if(g.name==="TypeError")return d.default_action(a,b);throw g}},d.canCompare=function(a,b){var c=a.getCommand().getLabel(),e=b.getCommand().getLabel();try{return d.compare[c][e](a,b)}catch(f){if(f.name==="TypeError")return d.default_compare(a,b);throw f}},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};var A={},B="jio/id_array";return A.id=1,A.storage=k.storage(a,z),function(){var a,b=LocalOrCookieStorage.getItem(B)||[];for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b)}(),function(){u.setId(A.id),u.start(),x.setId(A.id),x.start()}(),z.start=function(){x.start()},z.stop=function(){x.stop()},z.getId=function(){return A.id},z.validateStorageDescription=function(a){return k.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b){a=a||{};var c=a.type||"base";if(!e[c])throw d({type:c,message:"Storage does not exists."});return e[c](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return k}();
\ No newline at end of file
var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var d={};a=a||{},b=b||{};var e={};return e.type=a.type||"",d.getType=function(){return e.type},d.setType=function(a){e.type=a},d.execute=function(a){d.validate(a),a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){var b=d.validateState();if(b)throw c({storage:d,message:b});a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throw c({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d.validateState=function(){return""},d},i=function(a,b){var c=h(a,b);a=a||{},b=b||{};var d={};return d.storage_a=a.storagelist||[],c.beforeExecute=function(a){},c.execute=function(a){var b;c.validate(a),c.beforeExecute(a);for(b=0;b<d.storage_a.length;b++)d.storage_a[b].execute(a);c.afterExecute(a)},c.afterExecute=function(a){a.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){var d=function(a,c){var d={};a=a||{},c=c||{};var e={};return e.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,delete a.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){return e.path},d.getOption=function(a){return e.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){return e.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throw b({command:d,message:"Path is empty"})},d.done=function(a){e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d.canBeRestored=function(){return!0},d)},h=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c.canBeRestored=function(){return!1},c},i=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c.canBeRestored=function(){return!1},c},j=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){var e=d(a,c);a=a||{},c=c||{};var f={};f.content=a.content,e.getLabel=function(){return"saveDocument"},e.getContent=function(){return f.content};var g=e.validate;e.validate=function(a){if(typeof f.content!="string")throw b({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)};var h=e.serialized;return e.serialized=function(){var a=h();return a.content=f.content,a},e},m=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){var c=m(a,b);a=a||{},b=b||{};var d={};return d.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=new Date,function(){if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"})}(),c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return d.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"";return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),x=function(a,b){var c={};a=a||{},b=b||{};var e="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){return e+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a),f.removeJobArrayFromJioId(a))},f.restoreOldJobFromJioId=function(a){var b,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1){var f=d(e[b].command);f.canBeRestored()&&c.addJob(s({storage:k.storage(e[b].storage),command:f}))}},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d),LocalOrCookieStorage.deleteItem("jio/id/"+a)},f.removeJobArrayFromJioId=function(a){LocalOrCookieStorage.deleteItem("jio/job_array/"+a)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)return!0;return!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));return d},f.manage=function(a,b){var d;if(f.job_a.length!==b.length)throw new RangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){var c={},d={};return c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){return a.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){return a.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){var c,e,f;return c=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[c]&&d.action[c][f]&&d.action[c][f][e]?d.action[c][f][e](a,b):d.default_action(a,b)},d.canCompare=function(a,b){var c=a.getCommand().getLabel(),e=b.getCommand().getLabel();return d.compare[c]&&d.compare[e]?d.compare[c][e](a,b):d.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};var A={},B="jio/id_array";return A.id=null,A.storage=k.storage(a),A.init=function(){if(A.id===null){var a,b=LocalOrCookieStorage.getItem(B)||[];A.id=1;for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b),u.setId(A.id),x.setId(A.id)}},z.start=function(){A.init(),u.start(),x.start()},z.stop=function(){x.stop()},z.close=function(){u.stop(),x.stop(),A.id=null},z.start(),z.getId=function(){return A.id},z.validateStorageDescription=function(a){return k.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b,c){a=a||{};var f=c||a.type||"base";if(!e[f])throw d({type:f,message:"Storage does not exists."});return e[f](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return k}();
\ No newline at end of file
......@@ -10,9 +10,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok
var newDummyStorageAllOk = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
that.setType('dummyallok');
var that = Jio.storage( spec, my, 'base' );
that.saveDocument = function (command) {
// Tells us that the document is saved.
......@@ -74,7 +72,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail
newDummyStorageAllFail = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallfail');
......@@ -121,7 +119,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found
newDummyStorageAllNotFound = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallnotfound');
......@@ -167,7 +165,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries
newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ), priv = {};
var that = Jio.storage( spec, my, 'base' ), priv = {};
that.setType('dummyall3tries');
......
auto: grunt
check-syntax: grunt
grunt:
make -C ../../grunt/*_gruntJIO
......@@ -36,3 +36,4 @@ var activityUpdater = (function(spec, my) {
};
return that;
}());
......@@ -103,7 +103,6 @@ var command = function(spec, my) {
};
that.done = function(return_value) {
console.log ('done');
priv.done(return_value);
priv.respond({status:doneStatus(),value:return_value});
priv.end();
......@@ -113,7 +112,6 @@ var command = function(spec, my) {
if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) {
priv.retry();
} else {
console.log ('fail');
priv.fail(return_error);
priv.respond({status:failStatus(),error:return_error});
priv.end();
......@@ -142,5 +140,9 @@ var command = function(spec, my) {
option:priv.option};
};
that.canBeRestored = function() {
return true;
};
return that;
};
......@@ -12,5 +12,9 @@ var getDocumentList = function(spec, my) {
storage.getDocumentList(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -12,5 +12,9 @@ var loadDocument = function(spec, my) {
storage.loadDocument(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -3,14 +3,15 @@ var saveDocument = function(spec, my) {
spec = spec || {};
my = my || {};
// Attributes //
var content = spec.content;
var priv = {};
priv.content = spec.content;
// Methods //
that.getLabel = function() {
return 'saveDocument';
};
that.getContent = function() {
return content;
return priv.content;
};
/**
......@@ -19,7 +20,7 @@ var saveDocument = function(spec, my) {
*/
var super_validate = that.validate;
that.validate = function(handler) {
if (typeof content !== 'string') {
if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'});
}
super_validate(handler);
......@@ -29,5 +30,12 @@ var saveDocument = function(spec, my) {
storage.saveDocument(that);
};
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
};
return that;
};
......@@ -5,14 +5,16 @@
// Attributes //
var priv = {};
var jio_id_array_name = 'jio/id_array';
priv.id = 1;
priv.storage = jioNamespace.storage(spec, that);
priv.id = null;
priv.storage = jioNamespace.storage(spec);
// initialize //
(function () {
priv.init = function() {
// Initialize the jio id and add the new id to the list
var i,
jio_id_a = LocalOrCookieStorage.getItem (jio_id_array_name) || [];
if (priv.id === null) {
var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || [];
priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1;
......@@ -20,22 +22,26 @@
}
jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
}());
(function (){
// Start Jio updater, and the jobManager
activityUpdater.setId(priv.id);
activityUpdater.start();
jobManager.setId(priv.id);
jobManager.start();
}());
}
};
// Methods //
that.start = function() {
priv.init();
activityUpdater.start();
jobManager.start();
};
that.stop = function() {
jobManager.stop();
};
that.close = function() {
activityUpdater.stop();
jobManager.stop();
priv.id = null;
};
that.start();
/**
* Returns the jio id.
......
......@@ -12,11 +12,12 @@ var jioNamespace = (function(spec, my) {
* @method storage
* @param {object} spec The specifications.
* @param {object} my The protected object.
* @param {string} forcetype Force storage type
* @return {object} The storage object.
*/
that.storage = function(spec, my) {
that.storage = function(spec, my, forcetype) {
spec = spec || {};
var type = spec.type || 'base';
var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) {
throw invalidStorageType({type:type,
message:'Storage does not exists.'});
......
......@@ -122,7 +122,6 @@ var job = function(spec, my) {
* @param {object} job The other job.
*/
that.update = function(job) {
console.log ('updating');
priv.command.setMaxRetry(-1);
priv.command.fail({status:0,statusText:'Replaced',
message:'Job has been replaced by another one.'});
......
......@@ -92,6 +92,7 @@ var jobManager = (function(spec, my) {
if (jio_date < Date.now() - 10000) {
priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
}
};
......@@ -99,9 +100,12 @@ var jobManager = (function(spec, my) {
var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) {
var command_o = command(jio_job_array[i].command);
if (command_o.canBeRestored()) {
that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i]),
command:command(jio_job_array[i].command)}));
{storage:jioNamespace.storage(jio_job_array[i].storage),
command:command_o}));
}
}
};
......@@ -114,6 +118,11 @@ var jobManager = (function(spec, my) {
}
}
LocalOrCookieStorage.setItem('jio/id_array',new_a);
LocalOrCookieStorage.deleteItem('jio/id/'+id);
};
priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id);
};
/**
......@@ -138,11 +147,9 @@ var jobManager = (function(spec, my) {
var i;
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() === id) {
console.log ('found');
return true;
}
}
console.log ('not found');
return false;
};
......@@ -174,11 +181,9 @@ var jobManager = (function(spec, my) {
return;
}
}
console.log ('managing '+JSON.stringify (result_a));
for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) {
case 'eliminate':
console.log ('eliminating');
that.eliminate(result_a[i].job);
break;
case 'update':
......@@ -186,7 +191,6 @@ var jobManager = (function(spec, my) {
priv.copyJobArrayToLocal();
return;
case 'wait':
console.log ('wait');
job.waitForJob(result_a[i].job);
break;
default: break;
......@@ -201,7 +205,6 @@ var jobManager = (function(spec, my) {
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() !== job.getId()) {
tmp_a.push(priv.job_a[i]);
console.log ('add: '+priv.job_a[i].getId()+' -> it is not '+job.getId());
}
}
priv.job_a = tmp_a;
......
......@@ -138,30 +138,22 @@ var jobRules = (function(spec, my) {
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
try {
console.log (j1label);
console.log (j2label);
console.log (j1status);
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} catch (e) {
if(e.name==='TypeError') {
return priv.default_action(job1,job2);
} else {
throw e;
}
return priv.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
try {
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} catch(e) {
if (e.name==='TypeError') {
return priv.default_compare(job1,job2);
} else {
throw e;
}
return priv.default_compare(job1,job2);
}
};
that.validateJobAccordingToJob = function(job1,job2) {
......
......@@ -49,7 +49,6 @@ var waitStatus = function(spec, my) {
that.canStart = function() {
priv.refreshJobIdArray();
console.log (priv.job_id_a);
return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold);
};
that.canRestart = function() {
......
......@@ -21,6 +21,7 @@ var storage = function(spec, my) {
* @param {object} command The command
*/
that.execute = function(command) {
that.validate(command);
command.executeOn(that);
};
......@@ -34,6 +35,10 @@ var storage = function(spec, my) {
};
that.validate = function(command) {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
}
command.validate(that);
};
......@@ -59,5 +64,9 @@ var storage = function(spec, my) {
that.saveDocument();
};
that.validateState = function() {
return '';
};
return that;
};
......@@ -12,24 +12,22 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method beforeExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.beforeExecute = function(command,option) {};
that.beforeExecute = function(command) {};
/**
* Execute the command according to this storage.
* @method execute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.execute = function(command,option) {
that.execute = function(command) {
var i;
that.validate(command);
that.beforeExecute(command,option);
that.beforeExecute(command);
for(i = 0; i < priv.storage_a.length; i++) {
priv.storage_a[i].execute(command);
}
that.afterExecute(command,option);
that.afterExecute(command);
};
/**
......@@ -37,10 +35,9 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method afterExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.afterExecute = function(command,option) {
that.done();
that.afterExecute = function(command) {
command.done();
};
/**
......
......@@ -231,7 +231,6 @@ test ('Simple Job Elimination', function () {
'job creation');
o.jio.removeDocument('file',{onResponse:o.f2,max_retry:1});
o.tmp = LocalOrCookieStorage.getItem('jio/job_array/'+id)[0];
console.log (localStorage);
deepEqual(o.tmp.command.label,'removeDocument','job elimination');
});
......@@ -274,23 +273,18 @@ test ('Simple Job Waiting', function () {
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.id = o.jio.getId();
o.jio.saveDocument('file','content',{onResponse:o.f3,max_retry:1});
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.clock.tick(200);
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.jio.saveDocument('file','content1',{onResponse:o.f4,max_retry:1});
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.tmp0 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[0];
o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[1];
ok(o.tmp1 && o.tmp0.status.label === 'on going',
'The second job must not overwrite the first on going one.');
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
ok(o.tmp1.status.label === 'wait' &&
o.tmp1.status.waitforjob &&
JSON.stringify(o.tmp1.status.waitforjob) ===
JSON.stringify ([1]),
'The second job must be waiting for the first to end');
o.clock.tick(1000);
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
ok(o.f3.calledOnce,'first request passed');
ok(o.f4.calledOnce,'restore waiting job');
o.jio.stop();
......@@ -321,892 +315,867 @@ test ('Restore old Jio', function() {
o.f = function(result) {
ok(false,'must never be called!');
};
o.clock.tick(10000000);
o.clock.tick(0);
this.spy(o,'f');
o.jio = JIO.newJio({type:'dummyall3tries',applicationname:'jiotests'});
o.id = o.jio.getId();
o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:3});
o.clock.tick(1000);
o.jio.stop();
o.jio.close();
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.clock.tick(10000); // 10 sec
console.log (localStorage);
o.clock.tick(11000); // 10 sec
deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.id),null,
'job array list must be empty');
deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.jio.getId()),[],
'ee');
o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.jio.getId());
if (o.tmp1.length > 0) {
deepEqual([o.tmp1[0].command.label,o.tmp1[0].command.path,
o.tmp1[0].command.content],
['saveDocument','file','content'],
'job is restored' + o.jio.getId());
} else {
ok (false, 'The recovered job must exists');
}
});
module ( 'Jio LocalStorage' );
test ('Check name availability', function () {
// Test if LocalStorage can check the availabality of a name.
// We remove MrCheckName from local storage, and checking must return true.
// We now add MrCheckName to local storage, and checking must return false.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (value){
o.f = function (result) {
deepEqual(result.return_value,value,'checking name availabality');};
t.spy(o,'f');
o.jio.checkNameAvailability(
{'user_name':'MrCheckName','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
// new jio
o.jio = JIO.newJio({'type':'local','user_name':'noname'},
{"ID":'noid'});
// name must be available
removeFile ('MrCheckName','jiotests',{name:'file'});
mytest(true);
// name must be unavailable
addFile ('MrCheckName','jiotests',{name:'file'});
mytest(false);
o.jio.stop();
});
test ('Document save', function () {
// Test if LocalStorage can save documents.
// We launch a saving to localstorage and we check if the file is
// realy saved. Then save again and check if
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,lmcd){
o.f = function (result) {
deepEqual(result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument(
{'name':'file','content':'content','onResponse': o.f,
'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
o.spy = function(res,value,message) {
o.f = function(result) {
if (res === 'status') {
deepEqual (result.status.getLabel(),value,message);
} else {
// check content
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrSaveName/jiotests/file');
o.tmp.lmcd = lmcd(o.tmp.creation_date,o.tmp.last_modified);
delete o.tmp.last_modified;
delete o.tmp.creation_date;
deepEqual (o.tmp,{'name':'file','content':'content',
'lmcd':true},'check content');
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrSaveName'},
{"ID":'jiotests'});
LocalOrCookieStorage.deleteItem ('jio/local/MrSaveName/jiotests/file');
// save and check document existence
clock.tick(200);
// message, value, fun ( creationdate, lastmodified )
mytest('saving document','done',function(cd,lm){
return (cd === lm);
});
// re-save and check modification date
mytest('saving again','done',function(cd,lm){
return (cd < lm);
});
o.jio.stop();
});
test ('Document load', function () {
// Test if LocalStorage can load documents.
// We launch a loading from localstorage and we check if the file is
// realy loaded.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
doc = {},
mytest = function (res,value){
o.f = function (result) {
deepEqual(result[res],value,'loading document');};
t.spy(o,'f');
o.jio.loadDocument(
{'name':'file','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
deepEqual (result.value,value,message);
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrLoadName'},
{"ID":'jiotests'});
// load a non existing file
LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
mytest ('status','fail');
// re-load file after saving it manually
doc = {'name':'file','content':'content',
'last_modified':1234,'creation_date':1000};
LocalOrCookieStorage.setItem (
'jio/local_file_name_array/MrLoadName/jiotests',['file']);
LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
mytest ('return_value',doc);
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 = {}, clock = this.sandbox.useFakeTimers(), t = this,
doc1 = {}, doc2 = {},
mytest = function (value){
o.f = function (result) {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),'getting list');
o.t.spy(o,'f');
};
t.spy(o,'f');
o.jio.getDocumentList({'onResponse': o.f,'max_tries':1});
clock.tick(510);
o.tick = function (value, tick) {
o.clock.tick(tick || 1000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrListName'},
{"ID":'jiotests'});
doc1 = {'name':'file','content':'content',
'last_modified':1,'creation_date':0};
doc2 = {'name':'memo','content':'test',
'last_modified':5,'creation_date':2};
addFile ('MrListName','jiotests',doc1);
addFile ('MrListName','jiotests',doc2);
delete doc1.content;
delete doc2.content;
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
// realy removed.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (){
o.f = function (result) {
deepEqual(result.status,'done','removing document');};
t.spy(o,'f');
o.jio.removeDocument(
{'name':'file','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
o.tmp =
LocalOrCookieStorage.getItem ('jio/local/MrSaveName/jiotests/file');
if (o.tmp) {
o.tmp.lmcd = (o.tmp.last_modified === o.tmp.creation_date);
delete o.tmp.last_modified;
delete o.tmp.creation_date;
deepEqual (o.tmp,{name:'file',content:'content',lmcd:value},
'check saved document');
} else {
// check if the file is still there
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrRemoveName/jiotests/file');
ok (!o.tmp, 'check no content');
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrRemoveName'},
{"ID":'jiotests'});
// test removing a file
LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{});
mytest ();
o.jio.stop();
});
module ('Jio DAVStorage');
test ('Check name availability', function () {
// Test if DavStorage can check the availabality of a name.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (method,value,errno) {
var server = t.sandbox.useFakeServer();
server.respondWith ("PROPFIND",
"https://ca-davstorage:8080/dav/davcheck/",
[errno, {'Content-Type': 'text/xml' },
'']);
o.f = function (result) {
deepEqual(result[method],value,'checking name availability');};
t.spy(o,'f');
o.jio.checkNameAvailability({'user_name':'davcheck','onResponse':o.f,
'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
ok (false, 'document is not saved!');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davcheck',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// 404 error, the name does not exist, name is available.
mytest ('return_value',true,404);
// 200 error, responding ok, the name already exists, name is not available.
mytest ('return_value',false,200);
// 405 error, random error
mytest ('status','fail',405);
o.jio.stop();
});
o.jio = JIO.newJio({type:'local',username:'MrSaveName',
applicationname:'jiotests'});
// save and check document existence
o.spy('status','done','saving document');
o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:1});
o.tick(true);
test ('Document load', function () {
// Test if DavStorage can load documents.
var davload = getXML('responsexml/davload'),
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
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"'},
davload]);
server.respondWith (
"GET","https://ca-davstorage:8080/dav/davload/jiotests/file",
[errget,{},'content']);
o.f = function (result) {
deepEqual (result.return_value,doc,message);};
t.spy(o,'f');
o.jio.loadDocument({'name':'file','onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davload',
'password':'checkpwd',
'url':'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',undefined,404,404);
// load a document.
mytest ('load document',{'name':'file','content':'content',
'last_modified':1335953199000,
'creation_date':1335953202000},207,200);
o.jio.stop();
});
o.spy('status','done','saving document');
o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:1});
o.tick(false);
test ('Document save', function () {
// Test if DavStorage can save documents.
var davsave = getXML('responsexml/davsave'),
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,errnoput,errnoprop) {
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"'},
davsave]);
server.respondWith (
"PUT",
"https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoput, {'Content-Type':'x-www-form-urlencoded'},
'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.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument({'name':'file','content':'content',
'onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davsave',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// note: http errno:
// 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,201,404);
// the document does not exist, we want to create it
mytest('create document','done',201,404);
clock.tick(8000);
// the document already exists, we want to overwrite it
mytest('overwrite document','done',204,207);
o.jio.stop();
});
test ('Get Document List', function () {
// Test if DavStorage can get a list a document.
var davlist = getXML('responsexml/davlist'),
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
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"'},
davlist]);
o.f = function (result) {
if (result.status === 'fail') {
deepEqual (result.return_value, value, message);
} else {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),message);
}
};
t.spy(o,'f');
o.jio.getDocumentList({'onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davlist',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
mytest('fail to get list',undefined,404);
mytest('getting list',[{'name':'file','creation_date':1335962911000,
'last_modified':1335962907000},
{'name':'memo','creation_date':1335894073000,
'last_modified':1335955713000}],207);
o.jio.stop();
});
// test ('Document load', function () {
// // Test if LocalStorage can load documents.
// // We launch a loading from localstorage and we check if the file is
// // realy loaded.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// doc = {},
// mytest = function (res,value){
// o.f = function (result) {
// deepEqual(result[res],value,'loading document');};
// t.spy(o,'f');
// o.jio.loadDocument(
// {'name':'file','onResponse': o.f,'max_tries':1});
// clock.tick(510);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'local','user_name':'MrLoadName'},
// {"ID":'jiotests'});
// // load a non existing file
// LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
// mytest ('status','fail');
// // re-load file after saving it manually
// doc = {'name':'file','content':'content',
// 'last_modified':1234,'creation_date':1000};
// LocalOrCookieStorage.setItem (
// 'jio/local_file_name_array/MrLoadName/jiotests',['file']);
// LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
// mytest ('return_value',doc);
test ('Remove document', function () {
// Test if DavStorage can remove documents.
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
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.status,value,message);};
t.spy(o,'f');
o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davremove',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// 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 = {}, clock = this.sandbox.useFakeTimers(), t = this,
// doc1 = {}, doc2 = {},
// mytest = function (value){
// o.f = function (result) {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(value),'getting list');
// };
// t.spy(o,'f');
// o.jio.getDocumentList({'onResponse': o.f,'max_tries':1});
// clock.tick(510);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'local','user_name':'MrListName'},
// {"ID":'jiotests'});
// doc1 = {'name':'file','content':'content',
// 'last_modified':1,'creation_date':0};
// doc2 = {'name':'memo','content':'test',
// 'last_modified':5,'creation_date':2};
// addFile ('MrListName','jiotests',doc1);
// addFile ('MrListName','jiotests',doc2);
// delete doc1.content;
// delete doc2.content;
// mytest ([doc1,doc2]);
mytest('remove document','done',204);
mytest('remove an already removed document','done',404);
o.jio.stop();
});
// o.jio.stop();
// });
module ('Jio ReplicateStorage');
// test ('Document remove', function () {
// // Test if LocalStorage can remove documents.
// // We launch a remove from localstorage and we check if the file is
// // realy removed.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (){
// o.f = function (result) {
// deepEqual(result.status,'done','removing document');};
// t.spy(o,'f');
// o.jio.removeDocument(
// {'name':'file','onResponse': o.f,'max_tries':1});
// clock.tick(510);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// } else {
// // check if the file is still there
// o.tmp = LocalOrCookieStorage.getItem (
// 'jio/local/MrRemoveName/jiotests/file');
// ok (!o.tmp, 'check no content');
// }
// };
// o.jio = JIO.newJio({'type':'local','user_name':'MrRemoveName'},
// {"ID":'jiotests'});
// // test removing a file
// LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{});
// mytest ();
test ('Check name availability', function () {
// Tests the replicate storage
// method : checkNameAvailability
// It will test all the possibilities that could cause a server,
// like synchronisation problem...
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.return_value,value,message);
};
t.spy(o,'f');
o.jio.checkNameAvailability({'user_name':'Dummy','onResponse':o.f,
'max_tries':o.max_tries});
clock.tick(300000);
if (!o.f.calledOnce) {
ok(false,'no respose / too much results');
}
};
o.max_tries = 1;
// DummyStorageAllOK,OK
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllOK,OK : name available',true);
o.jio.stop();
// DummyStorageAllOK,Fail
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyallfail','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllOK,Fail : name not available',undefined);
o.jio.stop();
// DummyStorageAllFail,OK
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallfail','user_name':'1'},
{'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllFail,OK : name not available',undefined);
o.jio.stop();
// DummyStorageAllFail,Fail
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallfail','user_name':'1'},
{'type':'dummyallfail','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
o.jio.stop();
// DummyStorageAllOK,3Tries
o.max_tries = 3 ;
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllOK,3Tries : name available',true);
o.jio.stop();
// DummyStorageAll{3tries,{3tries,3tries},3tries}
o.max_tries = 3 ;
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyall3tries','user_name':'1'},
{'type':'replicate','storage_array':[
{'type':'dummyall3tries','user_name':'2'},
{'type':'dummyall3tries','user_name':'3'}]},
{'type':'dummyall3tries','user_name':'4'}]},
{'ID':'jiotests'});
mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',
true);
o.jio.stop();
});
// module ('Jio DAVStorage');
// test ('Check name availability', function () {
// // Test if DavStorage can check the availabality of a name.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (method,value,errno) {
// var server = t.sandbox.useFakeServer();
// server.respondWith ("PROPFIND",
// "https://ca-davstorage:8080/dav/davcheck/",
// [errno, {'Content-Type': 'text/xml' },
// '']);
// o.f = function (result) {
// deepEqual(result[method],value,'checking name availability');};
// t.spy(o,'f');
// o.jio.checkNameAvailability({'user_name':'davcheck','onResponse':o.f,
// 'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davcheck',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// // 404 error, the name does not exist, name is available.
// mytest ('return_value',true,404);
// // 200 error, responding ok, the name already exists, name is not available.
// mytest ('return_value',false,200);
// // 405 error, random error
// mytest ('status','fail',405);
test ('Document load', function () {
// Test if ReplicateStorage can load several documents.
// o.jio.stop();
// });
var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this;
var mytest = function (message,doc) {
o.f = function (result) {
deepEqual (result.return_value,doc,message);};
t.spy(o,'f');
o.jio.loadDocument({'name':'file','onResponse':o.f});
clock.tick(100000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,OK: load same file',{
'name':'file','content':'content',
'last_modified':15000,
'creation_date':10000});
o.jio.stop();
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: load 2 different files',{
'name':'file','content':'content',
'last_modified':15000,
'creation_date':10000});
// test ('Document load', function () {
// // Test if DavStorage can load documents.
// var davload = getXML('responsexml/davload'),
// o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// 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"'},
// davload]);
// server.respondWith (
// "GET","https://ca-davstorage:8080/dav/davload/jiotests/file",
// [errget,{},'content']);
// o.f = function (result) {
// deepEqual (result.return_value,doc,message);};
// t.spy(o,'f');
// o.jio.loadDocument({'name':'file','onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davload',
// 'password':'checkpwd',
// 'url':'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',undefined,404,404);
// // load a document.
// mytest ('load document',{'name':'file','content':'content',
// 'last_modified':1335953199000,
// 'creation_date':1335953202000},207,200);
// o.jio.stop();
// });
o.jio.stop();
});
// test ('Document save', function () {
// // Test if DavStorage can save documents.
// var davsave = getXML('responsexml/davsave'),
// o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value,errnoput,errnoprop) {
// 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"'},
// davsave]);
// server.respondWith (
// "PUT",
// "https://ca-davstorage:8080/dav/davsave/jiotests/file",
// [errnoput, {'Content-Type':'x-www-form-urlencoded'},
// '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.status,value,message);};
// t.spy(o,'f');
// o.jio.saveDocument({'name':'file','content':'content',
// 'onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davsave',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// // note: http errno:
// // 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,201,404);
// // the document does not exist, we want to create it
// mytest('create document','done',201,404);
// clock.tick(8000);
// // the document already exists, we want to overwrite it
// mytest('overwrite document','done',204,207);
// o.jio.stop();
// });
test ('Document save', function () {
// Test if ReplicateStorage can save several documents.
// test ('Get Document List', function () {
// // Test if DavStorage can get a list a document.
// var davlist = getXML('responsexml/davlist'),
// o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// 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"'},
// davlist]);
// o.f = function (result) {
// if (result.status === 'fail') {
// deepEqual (result.return_value, value, message);
// } else {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(value),message);
// }
// };
// t.spy(o,'f');
// o.jio.getDocumentList({'onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davlist',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// mytest('fail to get list',undefined,404);
// mytest('getting list',[{'name':'file','creation_date':1335962911000,
// 'last_modified':1335962907000},
// {'name':'memo','creation_date':1335894073000,
// 'last_modified':1335955713000}],207);
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument({'name':'file','content':'content',
'onResponse':o.f,'max_tries':3});
clock.tick(500);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyallok','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,OK: save a file.','done');
o.jio.stop();
});
// test ('Remove document', function () {
// // Test if DavStorage can remove documents.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// 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.status,value,message);};
// t.spy(o,'f');
// o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davremove',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// mytest('remove document','done',204);
// mytest('remove an already removed document','done',404);
// o.jio.stop();
// });
test ('Get Document List', function () {
// Test if ReplicateStorage can get several list.
// module ('Jio ReplicateStorage');
// test ('Check name availability', function () {
// // Tests the replicate storage
// // method : checkNameAvailability
// // It will test all the possibilities that could cause a server,
// // like synchronisation problem...
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (result.return_value,value,message);
// };
// t.spy(o,'f');
// o.jio.checkNameAvailability({'user_name':'Dummy','onResponse':o.f,
// 'max_tries':o.max_tries});
// clock.tick(300000);
// if (!o.f.calledOnce) {
// ok(false,'no respose / too much results');
// }
// };
// o.max_tries = 1;
// // DummyStorageAllOK,OK
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,OK : name available',true);
// o.jio.stop();
// // DummyStorageAllOK,Fail
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallfail','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,Fail : name not available',undefined);
// o.jio.stop();
// // DummyStorageAllFail,OK
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallfail','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllFail,OK : name not available',undefined);
// o.jio.stop();
// // DummyStorageAllFail,Fail
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallfail','user_name':'1'},
// {'type':'dummyallfail','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
// o.jio.stop();
// // DummyStorageAllOK,3Tries
// o.max_tries = 3 ;
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,3Tries : name available',true);
// o.jio.stop();
// // DummyStorageAll{3tries,{3tries,3tries},3tries}
// o.max_tries = 3 ;
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyall3tries','user_name':'1'},
// {'type':'replicate','storage_array':[
// {'type':'dummyall3tries','user_name':'2'},
// {'type':'dummyall3tries','user_name':'3'}]},
// {'type':'dummyall3tries','user_name':'4'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',
// true);
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),'getting list');
};
t.spy(o,'f');
o.jio.getDocumentList({'onResponse':o.f,'max_tries':3});
clock.tick(100000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'});
o.doc1 = {'name':'file',
'last_modified':15000,'creation_date':10000};
o.doc2 = {'name':'memo',
'last_modified':25000,'creation_date':20000};
mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]);
o.jio.stop();
});
// test ('Document load', function () {
// // Test if ReplicateStorage can load several documents.
// var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this;
// var mytest = function (message,doc) {
// o.f = function (result) {
// deepEqual (result.return_value,doc,message);};
// t.spy(o,'f');
// o.jio.loadDocument({'name':'file','onResponse':o.f});
// clock.tick(100000);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,OK: load same file',{
// 'name':'file','content':'content',
// 'last_modified':15000,
// 'creation_date':10000});
// o.jio.stop();
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,3tries: load 2 different files',{
// 'name':'file','content':'content',
// 'last_modified':15000,
// 'creation_date':10000});
test ('Remove document', function () {
// Test if ReplicateStorage can remove several documents.
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':3});
clock.tick(100000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: remove document.','done');
o.jio.stop();
});
// test ('Document save', function () {
// // Test if ReplicateStorage can save several documents.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (result.status,value,message);};
// t.spy(o,'f');
// o.jio.saveDocument({'name':'file','content':'content',
// 'onResponse':o.f,'max_tries':3});
// clock.tick(500);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,OK: save a file.','done');
// o.jio.stop();
// });
module ('Jio IndexedStorage');
// test ('Get Document List', function () {
// // Test if ReplicateStorage can get several list.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(value),'getting list');
// };
// t.spy(o,'f');
// o.jio.getDocumentList({'onResponse':o.f,'max_tries':3});
// clock.tick(100000);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// o.doc1 = {'name':'file',
// 'last_modified':15000,'creation_date':10000};
// o.doc2 = {'name':'memo',
// 'last_modified':25000,'creation_date':20000};
// mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]);
// o.jio.stop();
// });
test ('Check name availability', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.return_value,value,message);};
t.spy(o,'f');
o.jio.checkNameAvailability({user_name:'MrIndexedCheck',
onResponse:o.f,max_tries:3});
clock.tick(100000);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries',
user_name:'indexedcheck'}},
{ID:'jiotests'});
mytest('dummy ok : name must be available', true);
o.jio.stop();
});
// test ('Remove document', function () {
// // Test if ReplicateStorage can remove several documents.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (result.status,value,message);};
// t.spy(o,'f');
// o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':3});
// clock.tick(100000);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,3tries: remove document.','done');
// o.jio.stop();
// });
test ('Document load', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries',
user_name:'indexedload'}},
{ID:'jiotests'});
// loading must take long time with dummyall3tries
o.f = function () {};
this.spy(o,'f');
o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f,
options:{metadata_only:true}});
clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called');
// wait long time too retreive list
clock.tick(100000);
// now we can test if the document metadata are loaded faster.
o.doc = {name:'memo',last_modified:25000,creation_date:20000};
o.f2 = function (result) {
deepEqual (result.return_value,o.doc,'Document metadata retrieved');
};
this.spy(o,'f2');
o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f2,
options:{metadata_only:true}});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
// test a simple document loading
o.doc2 = {name:'file',last_modified:17000,
creation_date:11000,content:'content2'};
o.f3 = function (result) {
deepEqual (result.return_value,o.doc2,'Simple document loading');
};
this.spy(o,'f3');
o.jio.loadDocument({name:'file',max_tries:3,onResponse:o.f3});
clock.tick(100000);
if (!o.f3.calledOnce) {
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// module ('Jio IndexedStorage');
// test ('Check name availability', function () {
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (result.return_value,value,message);};
// t.spy(o,'f');
// o.jio.checkNameAvailability({user_name:'MrIndexedCheck',
// onResponse:o.f,max_tries:3});
// clock.tick(100000);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedcheck'}},
// {ID:'jiotests'});
// mytest('dummy ok : name must be available', true);
// o.jio.stop();
// });
test ('Document save', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries',
user_name:'indexedsave'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','document save');
};
this.spy(o,'f');
o.jio.saveDocument({name:'file',max_tries:3,onResponse:o.f});
clock.tick(100000);
if (!o.f.calledOnce){
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// test ('Document load', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedload'}},
// {ID:'jiotests'});
// // loading must take long time with dummyall3tries
// o.f = function () {};
// this.spy(o,'f');
// o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f,
// options:{metadata_only:true}});
// clock.tick(500);
// ok(!o.f.calledOnce,'Callback must not be called');
// // wait long time too retreive list
// clock.tick(100000);
// // now we can test if the document metadata are loaded faster.
// o.doc = {name:'memo',last_modified:25000,creation_date:20000};
// o.f2 = function (result) {
// deepEqual (result.return_value,o.doc,'Document metadata retrieved');
// };
// this.spy(o,'f2');
// o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f2,
// options:{metadata_only:true}});
// clock.tick(500);
// if (!o.f2.calledOnce) {
// ok (false, 'no response / too much results');
// }
// // test a simple document loading
// o.doc2 = {name:'file',last_modified:17000,
// creation_date:11000,content:'content2'};
// o.f3 = function (result) {
// deepEqual (result.return_value,o.doc2,'Simple document loading');
// };
// this.spy(o,'f3');
// o.jio.loadDocument({name:'file',max_tries:3,onResponse:o.f3});
// clock.tick(100000);
// if (!o.f3.calledOnce) {
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Get document list', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries',
user_name:'indexedgetlist'}},
{ID:'jiotests'});
o.doc1 = {name:'file',last_modified:15000,creation_date:10000};
o.doc2 = {name:'memo',last_modified:25000,creation_date:20000};
// getting list must take long time with dummyall3tries
o.f = function () {};
this.spy(o,'f');
o.jio.getDocumentList({max_tries:3,onResponse:o.f});
clock.tick(500);
ok(!o.f.calledOnce,'Callback must not be called');
// wail long time too retreive list
clock.tick(100000);
// now we can test if the document list is loaded faster
o.f2 = function (result) {
deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
};
this.spy(o,'f2');
o.jio.getDocumentList({max_tries:3,onResponse:o.f2});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
});
// test ('Document save', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedsave'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.status,'done','document save');
// };
// this.spy(o,'f');
// o.jio.saveDocument({name:'file',max_tries:3,onResponse:o.f});
// clock.tick(100000);
// if (!o.f.calledOnce){
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries',
user_name:'indexedsave'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','document remove');
};
this.spy(o,'f');
o.jio.removeDocument({name:'file',max_tries:3,onResponse:o.f});
clock.tick(100000);
if (!o.f.calledOnce){
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// test ('Get document list', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedgetlist'}},
// {ID:'jiotests'});
// o.doc1 = {name:'file',last_modified:15000,creation_date:10000};
// o.doc2 = {name:'memo',last_modified:25000,creation_date:20000};
// // getting list must take long time with dummyall3tries
// o.f = function () {};
// this.spy(o,'f');
// o.jio.getDocumentList({max_tries:3,onResponse:o.f});
// clock.tick(500);
// ok(!o.f.calledOnce,'Callback must not be called');
// // wail long time too retreive list
// clock.tick(100000);
// // now we can test if the document list is loaded faster
// o.f2 = function (result) {
// deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
// };
// this.spy(o,'f2');
// o.jio.getDocumentList({max_tries:3,onResponse:o.f2});
// clock.tick(500);
// if (!o.f2.calledOnce) {
// ok (false, 'no response / too much results');
// }
// });
module ('Jio CryptedStorage');
// test ('Remove document', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedsave'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.status,'done','document remove');
// };
// this.spy(o,'f');
// o.jio.removeDocument({name:'file',max_tries:3,onResponse:o.f});
// clock.tick(100000);
// if (!o.f.calledOnce){
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Check name availability' , function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted',
storage:{type:'local',
user_name:'cryptcheck'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.return_value,true,'name must be available');
};
this.spy(o,'f');
o.jio.checkNameAvailability({user_name:'cryptcheck',
max_tries:1,onResponse:o.f});
clock.tick(1000);
if (!o.f.calledOnce) {
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// module ('Jio CryptedStorage');
// test ('Check name availability' , function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'crypted',
// storage:{type:'local',
// user_name:'cryptcheck'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.return_value,true,'name must be available');
// };
// this.spy(o,'f');
// o.jio.checkNameAvailability({user_name:'cryptcheck',
// max_tries:1,onResponse:o.f});
// clock.tick(1000);
// if (!o.f.calledOnce) {
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Document save' , function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted',
user_name:'cryptsave',
password:'mypwd',
storage:{type:'local',
user_name:'cryptsavelocal'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','save ok');
};
this.spy(o,'f');
o.jio.saveDocument({name:'testsave',content:'contentoftest',
max_tries:1,onResponse:o.f});
clock.tick(1000);
if (!o.f.calledOnce) {
ok (false, 'no response / too much results');
}
// encrypt 'testsave' with 'cryptsave:mypwd' password
o.tmp = LocalOrCookieStorage.getItem(
'jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER/5x354bfX54QFa1');
if (o.tmp) {
delete o.tmp.last_modified;
delete o.tmp.creation_date;
}
deepEqual (o.tmp,
{name:'rZx5PJxttlf9QpZER/5x354bfX54QFa1',
content:'upZkPIpitF3QMT/DU5jM3gP0SEbwo1n81rMOfLE'},
'Check if the document is realy crypted');
o.jio.stop();
});
// test ('Document save' , function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'crypted',
// user_name:'cryptsave',
// password:'mypwd',
// storage:{type:'local',
// user_name:'cryptsavelocal'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.status,'done','save ok');
// };
// this.spy(o,'f');
// o.jio.saveDocument({name:'testsave',content:'contentoftest',
// max_tries:1,onResponse:o.f});
// clock.tick(1000);
// if (!o.f.calledOnce) {
// ok (false, 'no response / too much results');
// }
// // encrypt 'testsave' with 'cryptsave:mypwd' password
// o.tmp = LocalOrCookieStorage.getItem(
// 'jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER/5x354bfX54QFa1');
// if (o.tmp) {
// delete o.tmp.last_modified;
// delete o.tmp.creation_date;
// }
// deepEqual (o.tmp,
// {name:'rZx5PJxttlf9QpZER/5x354bfX54QFa1',
// content:'upZkPIpitF3QMT/DU5jM3gP0SEbwo1n81rMOfLE'},
// 'Check if the document is realy crypted');
// o.jio.stop();
// });
test ('Document Load' , function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted',
user_name:'cryptload',
password:'mypwd',
storage:{type:'local',
user_name:'cryptloadlocal'}},
{ID:'jiotests'});
o.f = function (result) {
if (result.status === 'done') {
deepEqual (result.return_value,
{name:'testload',
content:'contentoftest',
last_modified:500,
creation_date:500},
'load ok');
} else {
ok (false ,'cannot load');
}
};
this.spy(o,'f');
// encrypt 'testload' with 'cryptload:mypwd' password
// and 'contentoftest' with 'cryptload:mypwd'
LocalOrCookieStorage.setItem(
'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX',
{name:'mRyQFcUvUKq6tLGUjBo34P3oc2LPxEju',
content:'kSulH8Qo105dSKHcY2hEBXWXC9b+3PCEFSm1k7k',
last_modified:500,creation_date:500});
o.jio.loadDocument({name:'testload',
max_tries:1,onResponse:o.f});
clock.tick(1000);
if (!o.f.calledOnce) {
ok (false, 'no response / too much results');
}
o.jio.stop();
LocalOrCookieStorage.deleteItem(
'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX');
});
// test ('Document Load' , function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'crypted',
// user_name:'cryptload',
// password:'mypwd',
// storage:{type:'local',
// user_name:'cryptloadlocal'}},
// {ID:'jiotests'});
// o.f = function (result) {
// if (result.status === 'done') {
// deepEqual (result.return_value,
// {name:'testload',
// content:'contentoftest',
// last_modified:500,
// creation_date:500},
// 'load ok');
// } else {
// ok (false ,'cannot load');
// }
// };
// this.spy(o,'f');
// // encrypt 'testload' with 'cryptload:mypwd' password
// // and 'contentoftest' with 'cryptload:mypwd'
// LocalOrCookieStorage.setItem(
// 'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX',
// {name:'mRyQFcUvUKq6tLGUjBo34P3oc2LPxEju',
// content:'kSulH8Qo105dSKHcY2hEBXWXC9b+3PCEFSm1k7k',
// last_modified:500,creation_date:500});
// o.jio.loadDocument({name:'testload',
// max_tries:1,onResponse:o.f});
// clock.tick(1000);
// if (!o.f.calledOnce) {
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// LocalOrCookieStorage.deleteItem(
// 'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX');
// });
test ('Get Document List', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted',
user_name:'cryptgetlist',
password:'mypwd',
storage:{type:'local',
user_name:'cryptgetlistlocal'}},
{ID:'jiotests'});
o.f = function (result) {
if (result.status === 'done') {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(o.doc_list),'Getting list');
} else {
console.warn (result);
ok (false, 'Cannot get list');
}
};
this.spy(o,'f');
o.doc_list = [
{name:'testgetlist1',last_modified:500,creation_date:200},
{name:'testgetlist2',last_modified:300,creation_date:300}
];
o.doc_encrypt_list = [
{name:'541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw',
content:'/4dBPUdmLolLfUaDxPPrhjRPdA',
last_modified:500,creation_date:200},
{name:'541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw',
content:'/4FBALhweuyjxxD53eFQDSm4VA',
last_modified:300,creation_date:300}
];
// encrypt with 'cryptgetlist:mypwd' as password
LocalOrCookieStorage.setItem(
'jio/local_file_name_array/cryptgetlistlocal/jiotests',
[o.doc_encrypt_list[0].name,o.doc_encrypt_list[1].name]);
LocalOrCookieStorage.setItem(
'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[0].name,
o.doc_encrypt_list[0]);
LocalOrCookieStorage.setItem(
'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[1].name,
o.doc_encrypt_list[1]);
o.jio.getDocumentList({max_tries:1,onResponse:o.f});
clock.tick (2000);
if (!o.f.calledOnce) {
ok (false, 'no response / too much results');
}
clock.tick(1000);
o.jio.stop();
});
// test ('Get Document List', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'crypted',
// user_name:'cryptgetlist',
// password:'mypwd',
// storage:{type:'local',
// user_name:'cryptgetlistlocal'}},
// {ID:'jiotests'});
// o.f = function (result) {
// if (result.status === 'done') {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(o.doc_list),'Getting list');
// } else {
// console.warn (result);
// ok (false, 'Cannot get list');
// }
// };
// this.spy(o,'f');
// o.doc_list = [
// {name:'testgetlist1',last_modified:500,creation_date:200},
// {name:'testgetlist2',last_modified:300,creation_date:300}
// ];
// o.doc_encrypt_list = [
// {name:'541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw',
// content:'/4dBPUdmLolLfUaDxPPrhjRPdA',
// last_modified:500,creation_date:200},
// {name:'541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw',
// content:'/4FBALhweuyjxxD53eFQDSm4VA',
// last_modified:300,creation_date:300}
// ];
// // encrypt with 'cryptgetlist:mypwd' as password
// LocalOrCookieStorage.setItem(
// 'jio/local_file_name_array/cryptgetlistlocal/jiotests',
// [o.doc_encrypt_list[0].name,o.doc_encrypt_list[1].name]);
// LocalOrCookieStorage.setItem(
// 'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[0].name,
// o.doc_encrypt_list[0]);
// LocalOrCookieStorage.setItem(
// 'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[1].name,
// o.doc_encrypt_list[1]);
// o.jio.getDocumentList({max_tries:1,onResponse:o.f});
// clock.tick (2000);
// if (!o.f.calledOnce) {
// ok (false, 'no response / too much results');
// }
// clock.tick(1000);
// o.jio.stop();
// });
test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted',
user_name:'cryptremove',
password:'mypwd',
storage:{type:'local',
user_name:'cryptremovelocal'}},
{ID:'jiotests'});
o.f = function (result) {
deepEqual (result.status,'done','Document remove');
};
this.spy(o,'f');
// encrypt with 'cryptremove:mypwd' as password
LocalOrCookieStorage.setItem(
'jio/local_file_name_array/cryptremovelocal/jiotests',
["JqCLTjyxQqO9jwfxD/lyfGIX+qA"]);
LocalOrCookieStorage.setItem(
'jio/local/cryptremovelocal/jiotests/JqCLTjyxQqO9jwfxD/lyfGIX+qA',
{"name":"JqCLTjyxQqO9jwfxD/lyfGIX+qA",
"content":"LKaLZopWgML6IxERqoJ2mUyyO",
"creation_date":500,
"last_modified":500});
o.jio.removeDocument({name:'file',max_tries:1,onResponse:o.f});
clock.tick(1000);
if (!o.f.calledOnce){
ok (false, 'no response / too much results');
}
o.jio.stop();
});
// test ('Remove document', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'crypted',
// user_name:'cryptremove',
// password:'mypwd',
// storage:{type:'local',
// user_name:'cryptremovelocal'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.status,'done','Document remove');
// };
// this.spy(o,'f');
// // encrypt with 'cryptremove:mypwd' as password
// LocalOrCookieStorage.setItem(
// 'jio/local_file_name_array/cryptremovelocal/jiotests',
// ["JqCLTjyxQqO9jwfxD/lyfGIX+qA"]);
// LocalOrCookieStorage.setItem(
// 'jio/local/cryptremovelocal/jiotests/JqCLTjyxQqO9jwfxD/lyfGIX+qA',
// {"name":"JqCLTjyxQqO9jwfxD/lyfGIX+qA",
// "content":"LKaLZopWgML6IxERqoJ2mUyyO",
// "creation_date":500,
// "last_modified":500});
// o.jio.removeDocument({name:'file',max_tries:1,onResponse:o.f});
// clock.tick(1000);
// if (!o.f.calledOnce){
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
}; // end thisfun
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment