From 3d9061a14fd1b3062ba0e9a3024629004f5cb190 Mon Sep 17 00:00:00 2001 From: Dominic Bosch Date: Wed, 19 Feb 2014 06:53:37 +0100 Subject: [PATCH] removed unnecessary files from staging --- testing/.gitignore | 2 + testing/js/test.js | 93 ---- testing/js/test_config.js | 63 --- testing/js/test_db_interface.js | 567 --------------------- testing/js/test_logging.js | 121 ----- testing/js/test_persistence.js | 802 ------------------------------ testing/old/mod_config.js | 270 ---------- testing/old/mod_db_interface.js | 270 ---------- testing/old/mod_engine.js | 282 ----------- testing/old/mod_eventpoller.js | 144 ------ testing/old/mod_http_listener.js | 110 ---- testing/old/mod_logging.js | 32 -- testing/old/mod_module_loader.js | 74 --- testing/old/mod_module_manager.js | 103 ---- testing/old/mod_server.js | 81 --- testing/old/mod_user.js | 9 - testing/old/unit_integration.js | 7 - testing/old/whole_system.js | 18 - 18 files changed, 2 insertions(+), 3046 deletions(-) create mode 100644 testing/.gitignore delete mode 100644 testing/js/test.js delete mode 100644 testing/js/test_config.js delete mode 100644 testing/js/test_db_interface.js delete mode 100644 testing/js/test_logging.js delete mode 100644 testing/js/test_persistence.js delete mode 100644 testing/old/mod_config.js delete mode 100644 testing/old/mod_db_interface.js delete mode 100644 testing/old/mod_engine.js delete mode 100644 testing/old/mod_eventpoller.js delete mode 100644 testing/old/mod_http_listener.js delete mode 100644 testing/old/mod_logging.js delete mode 100644 testing/old/mod_module_loader.js delete mode 100644 testing/old/mod_module_manager.js delete mode 100644 testing/old/mod_server.js delete mode 100644 testing/old/mod_user.js delete mode 100644 testing/old/unit_integration.js delete mode 100644 testing/old/whole_system.js diff --git a/testing/.gitignore b/testing/.gitignore new file mode 100644 index 0000000..e1f8b99 --- /dev/null +++ b/testing/.gitignore @@ -0,0 +1,2 @@ +old/ +js/ \ No newline at end of file diff --git a/testing/js/test.js b/testing/js/test.js deleted file mode 100644 index 28509b5..0000000 --- a/testing/js/test.js +++ /dev/null @@ -1,93 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3378, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:16:04.664Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3401, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:16:54.083Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3419, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:18:01.073Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3426, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:18:37.414Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3468, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:21:37.843Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 3477, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T17:22:08.602Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 6213, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T20:23:53.091Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 6236, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T20:24:45.295Z", - "v": 0 - }); - - ({ - "name": "webapi-eca", - "hostname": "dominic-HPdv6", - "pid": 6260, - "level": 30, - "msg": "TL | custom path test 1", - "time": "2014-02-18T20:25:27.587Z", - "v": 0 - }); - -}).call(this); diff --git a/testing/js/test_config.js b/testing/js/test_config.js deleted file mode 100644 index e7e471f..0000000 --- a/testing/js/test_config.js +++ /dev/null @@ -1,63 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - var path, - _this = this; - - path = require('path'); - - exports.setUp = function(cb) { - var log, logger; - logger = require(path.join('..', 'js-coffee', 'logging')); - log = logger.getLogger({ - nolog: true - }); - _this.conf = require(path.join('..', 'js-coffee', 'config')); - _this.conf({ - logger: log - }); - return cb(); - }; - - exports.testRequire = function(test) { - test.expect(1); - test.ok(_this.conf.isReady(), 'File does not exist!'); - return test.done(); - }; - - exports.testParameters = function(test) { - var logconf, prop, reqProp, _i, _len; - reqProp = ['mode', 'io-level', 'file-level', 'file-path']; - test.expect(4 + reqProp.length); - test.ok(_this.conf.getHttpPort(), 'HTTP port does not exist!'); - test.ok(_this.conf.getDBPort(), 'DB port does not exist!'); - test.ok(_this.conf.getCryptoKey(), 'Crypto key does not exist!'); - logconf = _this.conf.getLogConf(); - test.ok(logconf, 'Log config does not exist!'); - for (_i = 0, _len = reqProp.length; _i < _len; _i++) { - prop = reqProp[_i]; - test.ok(logconf[prop], "Log conf property " + prop + " does not exist!"); - } - return test.done(); - }; - - exports.testDifferentConfigFile = function(test) { - test.expect(1); - _this.conf({ - nolog: true, - configPath: path.join('testing', 'files', 'jsonWrongConfig.json') - }); - test.ok(_this.conf.isReady(), 'Different path not loaded!'); - return test.done(); - }; - - exports.testNoConfigFile = function(test) { - test.expect(1); - _this.conf({ - nolog: true, - configPath: 'wrongpath.file' - }); - test.strictEqual(_this.conf.isReady(), false, 'Wrong path still loaded!'); - return test.done(); - }; - -}).call(this); diff --git a/testing/js/test_db_interface.js b/testing/js/test_db_interface.js deleted file mode 100644 index f808905..0000000 --- a/testing/js/test_db_interface.js +++ /dev/null @@ -1,567 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - var _this = this, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - exports.setUp = function(cb) { - _this.db = require('../js-coffee/db_interface'); - _this.db({ - logType: 2 - }); - return cb(); - }; - - exports.availability = { - testRequire: function(test) { - test.expect(1); - test.ok(_this.db, 'DB interface loaded'); - return test.done(); - }, - testConnect: function(test) { - test.expect(1); - return _this.db.isConnected(function(err) { - test.ifError(err, 'Connection failed!'); - return test.done(); - }); - }, - testNoConfig: function(test) { - test.expect(1); - _this.db({ - configPath: 'nonexistingconf.file' - }); - return _this.db.isConnected(function(err) { - test.ok(err, 'Still connected!?'); - return test.done(); - }); - }, - testWrongConfig: function(test) { - test.expect(1); - _this.db({ - configPath: 'testing/jsonWrongConfig.json' - }); - return _this.db.isConnected(function(err) { - test.ok(err, 'Still connected!?'); - return test.done(); - }); - }, - testPurgeQueue: function(test) { - var evt; - test.expect(2); - evt = { - eventid: '1', - event: 'mail' - }; - _this.db.pushEvent(evt); - _this.db.purgeEventQueue(); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during pop after purging!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - } - }; - - exports.events = { - setUp: function(cb) { - _this.evt1 = { - eventid: '1', - event: 'mail' - }; - _this.evt2 = { - eventid: '2', - event: 'mail' - }; - _this.db.purgeEventQueue(); - return cb(); - }, - testEmptyPopping: function(test) { - test.expect(2); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during pop after purging!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - }, - testEmptyPushing: function(test) { - test.expect(2); - _this.db.pushEvent(null); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during non-empty pushing!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - }, - testNonEmptyPopping: function(test) { - test.expect(3); - _this.db.pushEvent(_this.evt1); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during non-empty popping!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt1, obj, 'Wrong event in queue!'); - return test.done(); - }); - }, - testMultiplePushAndPops: function(test) { - var forkEnds, semaphore; - test.expect(6); - semaphore = 2; - forkEnds = function() { - if (--semaphore === 0) { - return test.done(); - } - }; - _this.db.pushEvent(_this.evt1); - _this.db.pushEvent(_this.evt2); - _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during multiple push and pop!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt1, obj, 'Wrong event in queue!'); - return forkEnds(); - }); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during multiple push and pop!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt2, obj, 'Wrong event in queue!'); - return forkEnds(); - }); - } - }; - - exports.action_invoker = { - testCreateAndRead: function(test) { - var action, id; - test.expect(3); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - _this.db.storeActionInvoker(id, action); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) >= 0, 'Expected key not in action-invokers set'); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, action, 'Retrieved Action Invoker is not what we expected'); - return _this.db.getActionInvokers(function(err, obj) { - test.deepEqual(action, obj[id], 'Action Invoker ist not in result set'); - _this.db.deleteActionInvoker(id); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - var action, actionNew, id; - test.expect(2); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - actionNew = 'unit-test action invoker new content'; - _this.db.storeActionInvoker(id, action); - _this.db.storeActionInvoker(id, actionNew); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, actionNew, 'Retrieved Action Invoker is not what we expected'); - return _this.db.getActionInvokers(function(err, obj) { - test.deepEqual(actionNew, obj[id], 'Action Invoker ist not in result set'); - _this.db.deleteActionInvoker(id); - return test.done(); - }); - }); - }, - testDelete: function(test) { - var action, id; - test.expect(2); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - _this.db.storeActionInvoker(id, action); - _this.db.deleteActionInvoker(id); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, null, 'Action Invoker still exists'); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) < 0, 'Action Invoker key still exists in set'); - return test.done(); - }); - }); - }, - testFetchSeveral: function(test) { - var action1, action1name, action2, action2name, fCheckInvoker, semaphore; - test.expect(3); - semaphore = 2; - action1name = 'test-action-invoker_1'; - action2name = 'test-action-invoker_2'; - action1 = 'unit-test action invoker 1 content'; - action2 = 'unit-test action invoker 2 content'; - fCheckInvoker = function(modname, mod) { - var forkEnds, myTest; - myTest = test; - forkEnds = function() { - if (--semaphore === 0) { - return myTest.done(); - } - }; - return function(err, obj) { - myTest.strictEqual(mod, obj, "Invoker " + modname + " does not equal the expected one"); - _this.db.deleteActionInvoker(modname); - return forkEnds(); - }; - }; - _this.db.storeActionInvoker(action1name, action1); - _this.db.storeActionInvoker(action2name, action2); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, action1name) >= 0 && __indexOf.call(obj, action2name) >= 0, 'Not all action invoker Ids in set'); - _this.db.getActionInvoker(action1name, fCheckInvoker(action1name, action1)); - return _this.db.getActionInvoker(action2name, fCheckInvoker(action2name, action2)); - }); - } - }; - - exports.action_invoker_params = { - testCreateAndRead: function(test) { - var actionId, params, userId; - test.expect(2); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeActionParams(actionId, userId, params); - return _this.db.getActionParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = actionId + ':' + userId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in action-params set'); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, params, 'Retrieved action params is not what we expected'); - _this.db.deleteActionParams(actionId, userId); - return test.done(); - }); - }); - }, - testUpdate: function(test) { - var actionId, params, paramsNew, userId; - test.expect(1); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - paramsNew = 'shouldn\'t this be a new object?'; - _this.db.storeActionParams(actionId, userId, params); - _this.db.storeActionParams(actionId, userId, paramsNew); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, paramsNew, 'Retrieved action params is not what we expected'); - _this.db.deleteActionParams(actionId, userId); - return test.done(); - }); - }, - testDelete: function(test) { - var actionId, params, userId; - test.expect(2); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeActionParams(actionId, userId, params); - _this.db.deleteActionParams(actionId, userId); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, null, 'Action params still exists'); - return _this.db.getActionParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = actionId + ':' + userId, __indexOf.call(obj, _ref) < 0), 'Action Params key still exists in set'); - return test.done(); - }); - }); - } - }; - - exports.event_poller = { - testCreateAndRead: function(test) { - var event, id; - test.expect(3); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - _this.db.storeEventPoller(id, event); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) >= 0, 'Expected key not in event-pollers set'); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, event, 'Retrieved Event Poller is not what we expected'); - return _this.db.getEventPollers(function(err, obj) { - test.deepEqual(event, obj[id], 'Event Poller ist not in result set'); - _this.db.deleteEventPoller(id); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - var event, eventNew, id; - test.expect(2); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - eventNew = 'unit-test event poller new content'; - _this.db.storeEventPoller(id, event); - _this.db.storeEventPoller(id, eventNew); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, eventNew, 'Retrieved Event Poller is not what we expected'); - return _this.db.getEventPollers(function(err, obj) { - test.deepEqual(eventNew, obj[id], 'Event Poller ist not in result set'); - _this.db.deleteEventPoller(id); - return test.done(); - }); - }); - }, - testDelete: function(test) { - var event, id; - test.expect(2); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - _this.db.storeEventPoller(id, event); - _this.db.deleteEventPoller(id); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, null, 'Event Poller still exists'); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) < 0, 'Event Poller key still exists in set'); - return test.done(); - }); - }); - }, - testFetchSeveral: function(test) { - var event1, event1name, event2, event2name, fCheckPoller, semaphore; - test.expect(3); - semaphore = 2; - event1name = 'test-event-poller_1'; - event2name = 'test-event-poller_2'; - event1 = 'unit-test event poller 1 content'; - event2 = 'unit-test event poller 2 content'; - fCheckPoller = function(modname, mod) { - var forkEnds, myTest; - myTest = test; - forkEnds = function() { - if (--semaphore === 0) { - return myTest.done(); - } - }; - return function(err, obj) { - myTest.strictEqual(mod, obj, "Invoker " + modname + " does not equal the expected one"); - _this.db.deleteEventPoller(modname); - return forkEnds(); - }; - }; - _this.db.storeEventPoller(event1name, event1); - _this.db.storeEventPoller(event2name, event2); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, event1name) >= 0 && __indexOf.call(obj, event2name) >= 0, 'Not all event poller Ids in set'); - _this.db.getEventPoller(event1name, fCheckPoller(event1name, event1)); - return _this.db.getEventPoller(event2name, fCheckPoller(event2name, event2)); - }); - } - }; - - exports.event_poller_params = { - testCreateAndRead: function(test) { - var eventId, params, userId; - test.expect(2); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeEventParams(eventId, userId, params); - return _this.db.getEventParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = eventId + ':' + userId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in event-params set'); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, params, 'Retrieved event params is not what we expected'); - _this.db.deleteEventParams(eventId, userId); - return test.done(); - }); - }); - }, - testUpdate: function(test) { - var eventId, params, paramsNew, userId; - test.expect(1); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - paramsNew = 'shouldn\'t this be a new object?'; - _this.db.storeEventParams(eventId, userId, params); - _this.db.storeEventParams(eventId, userId, paramsNew); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, paramsNew, 'Retrieved event params is not what we expected'); - _this.db.deleteEventParams(eventId, userId); - return test.done(); - }); - }, - testDelete: function(test) { - var eventId, params, userId; - test.expect(2); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeEventParams(eventId, userId, params); - _this.db.deleteEventParams(eventId, userId); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, null, 'Event params still exists'); - return _this.db.getEventParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = eventId + ':' + userId, __indexOf.call(obj, _ref) < 0), 'Event Params key still exists in set'); - return test.done(); - }); - }); - } - }; - - exports.rules = { - setUp: function(cb) { - _this.db({ - logType: 1 - }); - _this.userId = 'tester-1'; - _this.ruleId = 'test-rule_1'; - _this.rule = { - "id": "rule_id", - "event": "custom", - "condition": { - "property": "yourValue" - }, - "actions": [] - }; - _this.ruleNew = { - "id": "rule_new", - "event": "custom", - "condition": { - "property": "yourValue" - }, - "actions": [] - }; - return cb(); - }, - tearDown: function(cb) { - _this.db.deleteRule(_this.ruleId); - return cb(); - }, - testCreateAndRead: function(test) { - test.expect(3); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - return _this.db.getRuleIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in rule key set'); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.deepEqual(JSON.parse(obj), _this.rule, 'Retrieved rule is not what we expected'); - return _this.db.getRules(function(err, obj) { - test.deepEqual(_this.rule, JSON.parse(obj[_this.ruleId]), 'Rule not in result set'); - _this.db.deleteRule(_this.ruleId); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - test.expect(1); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.ruleNew)); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.deepEqual(JSON.parse(obj), _this.ruleNew, 'Retrieved rule is not what we expected'); - _this.db.deleteRule(_this.ruleId); - return test.done(); - }); - }, - testDelete: function(test) { - test.expect(2); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.deleteRule(_this.ruleId); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.strictEqual(obj, null, 'Rule still exists'); - return _this.db.getRuleIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) < 0), 'Rule key still exists in set'); - return test.done(); - }); - }); - }, - testLink: function(test) { - test.expect(2); - _this.db.linkRule(_this.ruleId, _this.userId); - return _this.db.getRuleLinkedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) >= 0), "Rule not linked to user " + _this.userId); - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) >= 0), "User not linked to rule " + _this.ruleId); - return test.done(); - }); - }); - }, - testUnlink: function(test) { - test.expect(2); - _this.db.linkRule(_this.ruleId, _this.userId); - _this.db.unlinkRule(_this.ruleId, _this.userId); - return _this.db.getRuleLinkedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) < 0), "Rule still linked to user " + _this.userId); - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "User still linked to rule " + _this.ruleId); - return test.done(); - }); - }); - }, - testActivate: function(test) { - var usr; - test.expect(3); - usr = { - username: "tester-1", - password: "tester-1" - }; - _this.db.storeUser(usr); - _this.db.activateRule(_this.ruleId, _this.userId); - return _this.db.getRuleActivatedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) >= 0), "Rule not activated for user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) >= 0), "User not activated for rule " + _this.ruleId); - return _this.db.getAllActivatedRuleIdsPerUser(function(err, obj) { - var _ref2; - test.ok(obj[_this.userId], "User not found in activated set"); - test.ok((_ref2 = _this.ruleId, __indexOf.call(obj[_this.userId], _ref2) >= 0), "Rule " + _this.ruleId + " not in activated rules set"); - return test.done(); - }); - }); - }); - }, - testDeactivate: function(test) { - test.expect(3); - _this.db.activateRule(_this.ruleId, _this.userId); - _this.db.deactivateRule(_this.ruleId, _this.userId); - return _this.db.getRuleActivatedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) < 0), "Rule still activated for user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "User still activated for rule " + _this.ruleId); - return _this.db.getAllActivatedRuleIdsPerUser(function(err, obj) { - var _ref2; - test.ok((_ref2 = _this.ruleId, __indexOf.call(obj[_this.userId], _ref2) < 0), "Rule " + _this.ruleId + " still in activated rules set"); - return test.done(); - }); - }); - }); - }, - testUnlinkAndDeactivateAfterDeletion: function(test) { - var fWaitForDeletion, fWaitForTest; - test.expect(2); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.linkRule(_this.ruleId, _this.userId); - _this.db.activateRule(_this.ruleId, _this.userId); - fWaitForTest = function() { - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) < 0), "Rule " + _this.ruleId + " still linked to user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "Rule " + _this.ruleId + " still activated for user " + _this.userId); - return test.done(); - }); - }); - }; - fWaitForDeletion = function() { - _this.db.deleteRule(_this.ruleId); - return setTimeout(fWaitForTest, 100); - }; - return setTimeout(fWaitForDeletion, 100); - } - }; - - exports.tearDown = function(cb) { - _this.db.shutDown(); - return cb(); - }; - -}).call(this); diff --git a/testing/js/test_logging.js b/testing/js/test_logging.js deleted file mode 100644 index 074b9f6..0000000 --- a/testing/js/test_logging.js +++ /dev/null @@ -1,121 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - var fs, getLog, path, - _this = this; - - path = require('path'); - - fs = require('fs'); - - getLog = function(strPath, cb) { - var fWait, - _this = this; - fWait = function() { - var arrStr, fConvertRow, i, row, str, _i, _len; - str = fs.readFileSync(path.resolve(strPath), 'utf-8'); - arrStr = str.split("\n"); - fConvertRow = function(row) { - try { - return JSON.parse(row); - } catch (_error) {} - }; - for (i = _i = 0, _len = arrStr.length; _i < _len; i = ++_i) { - row = arrStr[i]; - arrStr[i] = fConvertRow(row); - } - return cb(arrStr.slice(0, arrStr.length - 1)); - }; - return setTimeout(fWait, 100); - }; - - exports.setUp = function(cb) { - _this.stdPath = path.resolve(__dirname, '..', 'logs', 'server.log'); - try { - fs.unlinkSync(_this.stdPath); - } catch (_error) {} - _this.logger = require(path.join('..', 'js-coffee', 'logging')); - return cb(); - }; - - exports.testCreate = function(test) { - var args, arrLogs, log; - test.expect(2); - arrLogs = ['TL | testInitIO - info', 'TL | testInitIO - warn', 'TL | testInitIO - error']; - args = {}; - args['io-level'] = 'error'; - log = _this.logger.getLogger(args); - log.info(arrLogs[0]); - log.warn(arrLogs[1]); - log.error(arrLogs[2]); - test.ok(fs.existsSync(_this.stdPath), 'Log file does not exist!'); - return getLog(_this.stdPath, function(arr) { - var allCorrect, i, o, _i, _len; - allCorrect = true; - for (i = _i = 0, _len = arr.length; _i < _len; i = ++_i) { - o = arr[i]; - if (o.msg === !arrLogs[i]) { - allCorrect = false; - } - } - test.ok(allCorrect, 'Log file does not contain the correct entries!'); - return test.done(); - }); - }; - - exports.testNoLog = function(test) { - var fWait, log; - test.expect(1); - log = _this.logger.getLogger({ - nolog: true - }); - log.info('TL | test 1'); - fWait = function() { - test.ok(!fs.existsSync(_this.stdPath), 'Log file does still exist!'); - return test.done(); - }; - return setTimeout(fWait, 100); - }; - - exports.testCustomPath = function(test) { - var args, fWait, log, strInfo, strPath; - test.expect(2); - strInfo = 'TL | custom path test 1'; - strPath = 'testing/test.log'; - args = {}; - args['file-path'] = strPath; - args['io-level'] = 'error'; - log = _this.logger.getLogger(args); - log.info(strInfo); - fWait = function() { - test.ok(fs.existsSync(strPath), 'Custom log file does not exist!'); - return getLog(strPath, function(arr) { - test.ok(arr[0].msg === strInfo, 'Custom log file not correct!'); - return test.done(); - }); - }; - return setTimeout(fWait, 100); - }; - - exports.testWrongPath = function(test) { - var args, fWait, log, strInfo, strPath; - test.expect(1); - strInfo = 'TL | custom path test 1'; - strPath = 'strange/path/to/test.log'; - args = {}; - args['file-path'] = strPath; - args['io-level'] = 'error'; - console.log('getting logger'); - log = _this.logger.getLogger(args); - console.log('logging'); - log.info(strInfo); - console.log('logged'); - fWait = function() { - console.log('waited'); - test.ok(true, 'Custom log file does not exist!'); - return test.done(); - }; - console.log('timing'); - return setTimeout(fWait, 100); - }; - -}).call(this); diff --git a/testing/js/test_persistence.js b/testing/js/test_persistence.js deleted file mode 100644 index 19d484c..0000000 --- a/testing/js/test_persistence.js +++ /dev/null @@ -1,802 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - var _this = this, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - exports.setUp = function(cb) { - var logger; - _this.path = require('path'); - logger = require(_this.path.join('..', 'js-coffee', 'logging')); - _this.log = logger.getLogger({ - nolog: true - }); - _this.db = require(_this.path.join('..', 'js-coffee', 'persistence')); - _this.db({ - logger: _this.log - }); - return cb(); - }; - - exports.tearDown = function(cb) { - var _ref; - if ((_ref = _this.db) != null) { - _ref.shutDown(); - } - return cb(); - }; - - /* - # Test AVAILABILITY - */ - - - exports.Availability = { - testRequire: function(test) { - test.expect(1); - test.ok(_this.db, 'DB interface loaded'); - return test.done(); - }, - testConnect: function(test) { - test.expect(1); - return _this.db.isConnected(function(err) { - test.ifError(err, 'Connection failed!'); - return test.done(); - }); - }, - testNoConfig: function(test) { - test.expect(1); - _this.db({ - logger: _this.log, - configPath: 'nonexistingconf.file' - }); - return _this.db.isConnected(function(err) { - test.ok(err, 'Still connected!?'); - return test.done(); - }); - }, - testWrongConfig: function(test) { - test.expect(1); - _this.db({ - logger: _this.log, - configPath: _this.path.join('testing', 'jsonWrongConfig.json') - }); - return _this.db.isConnected(function(err) { - test.ok(err, 'Still connected!?'); - return test.done(); - }); - }, - testPurgeQueue: function(test) { - var evt; - test.expect(2); - evt = { - eventid: '1', - event: 'mail' - }; - _this.db.pushEvent(evt); - _this.db.purgeEventQueue(); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during pop after purging!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - } - }; - - /* - # Test EVENT QUEUE - */ - - - exports.EventQueue = { - setUp: function(cb) { - _this.evt1 = { - eventid: '1', - event: 'mail' - }; - _this.evt2 = { - eventid: '2', - event: 'mail' - }; - _this.db.purgeEventQueue(); - return cb(); - }, - testEmptyPopping: function(test) { - test.expect(2); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during pop after purging!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - }, - testEmptyPushing: function(test) { - test.expect(2); - _this.db.pushEvent(null); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during non-empty pushing!'); - test.strictEqual(obj, null, 'There was an event in the queue!?'); - return test.done(); - }); - }, - testNonEmptyPopping: function(test) { - test.expect(3); - _this.db.pushEvent(_this.evt1); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during non-empty popping!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt1, obj, 'Wrong event in queue!'); - return test.done(); - }); - }, - testMultiplePushAndPops: function(test) { - var forkEnds, semaphore; - test.expect(6); - semaphore = 2; - forkEnds = function() { - if (--semaphore === 0) { - return test.done(); - } - }; - _this.db.pushEvent(_this.evt1); - _this.db.pushEvent(_this.evt2); - _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during multiple push and pop!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt1, obj, 'Wrong event in queue!'); - return forkEnds(); - }); - return _this.db.popEvent(function(err, obj) { - test.ifError(err, 'Error during multiple push and pop!'); - test.notStrictEqual(obj, null, 'There was no event in the queue!'); - test.deepEqual(_this.evt2, obj, 'Wrong event in queue!'); - return forkEnds(); - }); - } - }; - - /* - # Test ACTION INVOKER - */ - - - exports.ActionInvoker = { - testCreateAndRead: function(test) { - var action, id; - test.expect(3); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - _this.db.storeActionInvoker(id, action); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) >= 0, 'Expected key not in action-invokers set'); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, action, 'Retrieved Action Invoker is not what we expected'); - return _this.db.getActionInvokers(function(err, obj) { - test.deepEqual(action, obj[id], 'Action Invoker ist not in result set'); - _this.db.deleteActionInvoker(id); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - var action, actionNew, id; - test.expect(2); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - actionNew = 'unit-test action invoker new content'; - _this.db.storeActionInvoker(id, action); - _this.db.storeActionInvoker(id, actionNew); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, actionNew, 'Retrieved Action Invoker is not what we expected'); - return _this.db.getActionInvokers(function(err, obj) { - test.deepEqual(actionNew, obj[id], 'Action Invoker ist not in result set'); - _this.db.deleteActionInvoker(id); - return test.done(); - }); - }); - }, - testDelete: function(test) { - var action, id; - test.expect(2); - id = 'test-action-invoker'; - action = 'unit-test action invoker content'; - _this.db.storeActionInvoker(id, action); - _this.db.deleteActionInvoker(id); - return _this.db.getActionInvoker(id, function(err, obj) { - test.strictEqual(obj, null, 'Action Invoker still exists'); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) < 0, 'Action Invoker key still exists in set'); - return test.done(); - }); - }); - }, - testFetchSeveral: function(test) { - var action1, action1name, action2, action2name, fCheckInvoker, semaphore; - test.expect(3); - semaphore = 2; - action1name = 'test-action-invoker_1'; - action2name = 'test-action-invoker_2'; - action1 = 'unit-test action invoker 1 content'; - action2 = 'unit-test action invoker 2 content'; - fCheckInvoker = function(modname, mod) { - var forkEnds, myTest; - myTest = test; - forkEnds = function() { - if (--semaphore === 0) { - return myTest.done(); - } - }; - return function(err, obj) { - myTest.strictEqual(mod, obj, "Invoker " + modname + " does not equal the expected one"); - _this.db.deleteActionInvoker(modname); - return forkEnds(); - }; - }; - _this.db.storeActionInvoker(action1name, action1); - _this.db.storeActionInvoker(action2name, action2); - return _this.db.getActionInvokerIds(function(err, obj) { - test.ok(__indexOf.call(obj, action1name) >= 0 && __indexOf.call(obj, action2name) >= 0, 'Not all action invoker Ids in set'); - _this.db.getActionInvoker(action1name, fCheckInvoker(action1name, action1)); - return _this.db.getActionInvoker(action2name, fCheckInvoker(action2name, action2)); - }); - } - }; - - /* - # Test ACTION INVOKER PARAMS - */ - - - exports.ActionInvokerParams = { - testCreateAndRead: function(test) { - var actionId, params, userId; - test.expect(2); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeActionParams(actionId, userId, params); - return _this.db.getActionParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = actionId + ':' + userId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in action-params set'); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, params, 'Retrieved action params is not what we expected'); - _this.db.deleteActionParams(actionId, userId); - return test.done(); - }); - }); - }, - testUpdate: function(test) { - var actionId, params, paramsNew, userId; - test.expect(1); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - paramsNew = 'shouldn\'t this be a new object?'; - _this.db.storeActionParams(actionId, userId, params); - _this.db.storeActionParams(actionId, userId, paramsNew); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, paramsNew, 'Retrieved action params is not what we expected'); - _this.db.deleteActionParams(actionId, userId); - return test.done(); - }); - }, - testDelete: function(test) { - var actionId, params, userId; - test.expect(2); - userId = 'tester1'; - actionId = 'test-action-invoker_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeActionParams(actionId, userId, params); - _this.db.deleteActionParams(actionId, userId); - return _this.db.getActionParams(actionId, userId, function(err, obj) { - test.strictEqual(obj, null, 'Action params still exists'); - return _this.db.getActionParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = actionId + ':' + userId, __indexOf.call(obj, _ref) < 0), 'Action Params key still exists in set'); - return test.done(); - }); - }); - } - }; - - /* - # Test EVENT POLLER - */ - - - exports.EventPoller = { - testCreateAndRead: function(test) { - var event, id; - test.expect(3); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - _this.db.storeEventPoller(id, event); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) >= 0, 'Expected key not in event-pollers set'); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, event, 'Retrieved Event Poller is not what we expected'); - return _this.db.getEventPollers(function(err, obj) { - test.deepEqual(event, obj[id], 'Event Poller ist not in result set'); - _this.db.deleteEventPoller(id); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - var event, eventNew, id; - test.expect(2); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - eventNew = 'unit-test event poller new content'; - _this.db.storeEventPoller(id, event); - _this.db.storeEventPoller(id, eventNew); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, eventNew, 'Retrieved Event Poller is not what we expected'); - return _this.db.getEventPollers(function(err, obj) { - test.deepEqual(eventNew, obj[id], 'Event Poller ist not in result set'); - _this.db.deleteEventPoller(id); - return test.done(); - }); - }); - }, - testDelete: function(test) { - var event, id; - test.expect(2); - id = 'test-event-poller'; - event = 'unit-test event poller content'; - _this.db.storeEventPoller(id, event); - _this.db.deleteEventPoller(id); - return _this.db.getEventPoller(id, function(err, obj) { - test.strictEqual(obj, null, 'Event Poller still exists'); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, id) < 0, 'Event Poller key still exists in set'); - return test.done(); - }); - }); - }, - testFetchSeveral: function(test) { - var event1, event1name, event2, event2name, fCheckPoller, semaphore; - test.expect(3); - semaphore = 2; - event1name = 'test-event-poller_1'; - event2name = 'test-event-poller_2'; - event1 = 'unit-test event poller 1 content'; - event2 = 'unit-test event poller 2 content'; - fCheckPoller = function(modname, mod) { - var forkEnds, myTest; - myTest = test; - forkEnds = function() { - if (--semaphore === 0) { - return myTest.done(); - } - }; - return function(err, obj) { - myTest.strictEqual(mod, obj, "Invoker " + modname + " does not equal the expected one"); - _this.db.deleteEventPoller(modname); - return forkEnds(); - }; - }; - _this.db.storeEventPoller(event1name, event1); - _this.db.storeEventPoller(event2name, event2); - return _this.db.getEventPollerIds(function(err, obj) { - test.ok(__indexOf.call(obj, event1name) >= 0 && __indexOf.call(obj, event2name) >= 0, 'Not all event poller Ids in set'); - _this.db.getEventPoller(event1name, fCheckPoller(event1name, event1)); - return _this.db.getEventPoller(event2name, fCheckPoller(event2name, event2)); - }); - } - }; - - /* - # Test EVENT POLLER PARAMS - */ - - - exports.EventPollerParams = { - testCreateAndRead: function(test) { - var eventId, params, userId; - test.expect(2); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeEventParams(eventId, userId, params); - return _this.db.getEventParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = eventId + ':' + userId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in event-params set'); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, params, 'Retrieved event params is not what we expected'); - _this.db.deleteEventParams(eventId, userId); - return test.done(); - }); - }); - }, - testUpdate: function(test) { - var eventId, params, paramsNew, userId; - test.expect(1); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - paramsNew = 'shouldn\'t this be a new object?'; - _this.db.storeEventParams(eventId, userId, params); - _this.db.storeEventParams(eventId, userId, paramsNew); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, paramsNew, 'Retrieved event params is not what we expected'); - _this.db.deleteEventParams(eventId, userId); - return test.done(); - }); - }, - testDelete: function(test) { - var eventId, params, userId; - test.expect(2); - userId = 'tester1'; - eventId = 'test-event-poller_1'; - params = 'shouldn\'t this be an object?'; - _this.db.storeEventParams(eventId, userId, params); - _this.db.deleteEventParams(eventId, userId); - return _this.db.getEventParams(eventId, userId, function(err, obj) { - test.strictEqual(obj, null, 'Event params still exists'); - return _this.db.getEventParamsIds(function(err, obj) { - var _ref; - test.ok((_ref = eventId + ':' + userId, __indexOf.call(obj, _ref) < 0), 'Event Params key still exists in set'); - return test.done(); - }); - }); - } - }; - - /* - # Test RULES - */ - - - exports.Rules = { - setUp: function(cb) { - _this.userId = 'tester-1'; - _this.ruleId = 'test-rule_1'; - _this.rule = { - "id": "rule_id", - "event": "custom", - "condition": { - "property": "yourValue" - }, - "actions": [] - }; - _this.ruleNew = { - "id": "rule_new", - "event": "custom", - "condition": { - "property": "yourValue" - }, - "actions": [] - }; - return cb(); - }, - tearDown: function(cb) { - _this.db.deleteRule(_this.ruleId); - return cb(); - }, - testCreateAndRead: function(test) { - test.expect(3); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - return _this.db.getRuleIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) >= 0), 'Expected key not in rule key set'); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.deepEqual(JSON.parse(obj), _this.rule, 'Retrieved rule is not what we expected'); - return _this.db.getRules(function(err, obj) { - test.deepEqual(_this.rule, JSON.parse(obj[_this.ruleId]), 'Rule not in result set'); - _this.db.deleteRule(_this.ruleId); - return test.done(); - }); - }); - }); - }, - testUpdate: function(test) { - test.expect(1); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.ruleNew)); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.deepEqual(JSON.parse(obj), _this.ruleNew, 'Retrieved rule is not what we expected'); - _this.db.deleteRule(_this.ruleId); - return test.done(); - }); - }, - testDelete: function(test) { - test.expect(2); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.deleteRule(_this.ruleId); - return _this.db.getRule(_this.ruleId, function(err, obj) { - test.strictEqual(obj, null, 'Rule still exists'); - return _this.db.getRuleIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) < 0), 'Rule key still exists in set'); - return test.done(); - }); - }); - }, - testLink: function(test) { - test.expect(2); - _this.db.linkRule(_this.ruleId, _this.userId); - return _this.db.getRuleLinkedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) >= 0), "Rule not linked to user " + _this.userId); - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) >= 0), "User not linked to rule " + _this.ruleId); - return test.done(); - }); - }); - }, - testUnlink: function(test) { - test.expect(2); - _this.db.linkRule(_this.ruleId, _this.userId); - _this.db.unlinkRule(_this.ruleId, _this.userId); - return _this.db.getRuleLinkedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) < 0), "Rule still linked to user " + _this.userId); - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "User still linked to rule " + _this.ruleId); - return test.done(); - }); - }); - }, - testActivate: function(test) { - var usr; - test.expect(4); - usr = { - username: "tester-1", - password: "tester-1" - }; - _this.db.storeUser(usr); - _this.db.activateRule(_this.ruleId, _this.userId); - return _this.db.getRuleActivatedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) >= 0), "Rule not activated for user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) >= 0), "User not activated for rule " + _this.ruleId); - return _this.db.getAllActivatedRuleIdsPerUser(function(err, obj) { - var _ref2; - test.notStrictEqual(obj[_this.userId], void 0, "User " + _this.userId + " not in activated rules set"); - if (obj[_this.userId]) { - test.ok((_ref2 = _this.ruleId, __indexOf.call(obj[_this.userId], _ref2) >= 0), "Rule " + _this.ruleId + " not in activated rules set"); - } - return test.done(); - }); - }); - }); - }, - testDeactivate: function(test) { - test.expect(3); - _this.db.activateRule(_this.ruleId, _this.userId); - _this.db.deactivateRule(_this.ruleId, _this.userId); - return _this.db.getRuleActivatedUsers(_this.ruleId, function(err, obj) { - var _ref; - test.ok((_ref = _this.userId, __indexOf.call(obj, _ref) < 0), "Rule still activated for user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "User still activated for rule " + _this.ruleId); - return _this.db.getAllActivatedRuleIdsPerUser(function(err, obj) { - var _ref2; - if (obj[_this.userId]) { - test.ok((_ref2 = _this.ruleId, __indexOf.call(obj[_this.userId], _ref2) < 0), "Rule " + _this.ruleId + " still in activated rules set"); - } else { - test.ok(true, "We are fine since there are no entries for this user anymore"); - } - return test.done(); - }); - }); - }); - }, - testUnlinkAndDeactivateAfterDeletion: function(test) { - var fWaitForDeletion, fWaitForTest; - test.expect(2); - _this.db.storeRule(_this.ruleId, JSON.stringify(_this.rule)); - _this.db.linkRule(_this.ruleId, _this.userId); - _this.db.activateRule(_this.ruleId, _this.userId); - fWaitForTest = function() { - return _this.db.getUserLinkedRules(_this.userId, function(err, obj) { - var _ref; - test.ok((_ref = _this.ruleId, __indexOf.call(obj, _ref) < 0), "Rule " + _this.ruleId + " still linked to user " + _this.userId); - return _this.db.getUserActivatedRules(_this.userId, function(err, obj) { - var _ref1; - test.ok((_ref1 = _this.ruleId, __indexOf.call(obj, _ref1) < 0), "Rule " + _this.ruleId + " still activated for user " + _this.userId); - return test.done(); - }); - }); - }; - fWaitForDeletion = function() { - _this.db.deleteRule(_this.ruleId); - return setTimeout(fWaitForTest, 100); - }; - return setTimeout(fWaitForDeletion, 100); - } - }; - - /* - # Test USER - */ - - - exports.User = { - setUp: function(cb) { - _this.oUser = { - username: "tester-1", - password: "password" - }; - return cb(); - }, - tearDown: function(cb) { - _this.db.deleteUser(_this.oUser.username); - return cb(); - }, - testCreateInvalid: function(test) { - var oUserInvOne, oUserInvTwo; - test.expect(4); - oUserInvOne = { - username: "tester-1-invalid" - }; - oUserInvTwo = { - password: "password" - }; - _this.db.storeUser(oUserInvOne); - _this.db.storeUser(oUserInvTwo); - return _this.db.getUser(oUserInvOne.username, function(err, obj) { - test.strictEqual(obj, null, 'User One was stored!?'); - return _this.db.getUser(oUserInvTwo.username, function(err, obj) { - test.strictEqual(obj, null, 'User Two was stored!?'); - return _this.db.getUserIds(function(err, obj) { - var _ref, _ref1; - test.ok((_ref = oUserInvOne.username, __indexOf.call(obj, _ref) < 0), 'User key was stored!?'); - test.ok((_ref1 = oUserInvTwo.username, __indexOf.call(obj, _ref1) < 0), 'User key was stored!?'); - return test.done(); - }); - }); - }); - }, - testDelete: function(test) { - test.expect(2); - _this.db.storeUser(_this.oUser); - return _this.db.getUser(_this.oUser.username, function(err, obj) { - test.deepEqual(obj, _this.oUser, "User " + _this.oUser.username + " is not what we expect!"); - return _this.db.getUserIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.oUser.username, __indexOf.call(obj, _ref) >= 0), 'User key was not stored!?'); - return test.done(); - }); - }); - }, - testUpdate: function(test) { - var oUserOne; - test.expect(2); - oUserOne = { - username: "tester-1-update", - password: "password" - }; - _this.db.storeUser(oUserOne); - oUserOne.password = "password-update"; - _this.db.storeUser(oUserOne); - return _this.db.getUser(oUserOne.username, function(err, obj) { - test.deepEqual(obj, oUserOne, "User " + _this.oUser.username + " is not what we expect!"); - return _this.db.getUserIds(function(err, obj) { - var _ref; - test.ok((_ref = oUserOne.username, __indexOf.call(obj, _ref) >= 0), 'User key was not stored!?'); - _this.db.deleteUser(oUserOne.username); - return test.done(); - }); - }); - }, - testDelete: function(test) { - var fWaitForDeletion; - test.expect(2); - fWaitForDeletion = function() { - return _this.db.getUserIds(function(err, obj) { - var _ref; - test.ok((_ref = _this.oUser.username, __indexOf.call(obj, _ref) < 0), 'User key still in set!'); - return _this.db.getUser(_this.oUser.username, function(err, obj) { - test.strictEqual(obj, null, 'User key still exists!'); - return test.done(); - }); - }); - }; - _this.db.storeUser(_this.oUser); - _this.db.deleteUser(_this.oUser.username); - return setTimeout(fWaitForDeletion, 100); - }, - testDeleteLinks: function(test) { - var fWaitForDeletion, fWaitForPersistence; - test.expect(4); - fWaitForPersistence = function() { - _this.db.deleteUser(_this.oUser.username); - return setTimeout(fWaitForDeletion, 200); - }; - fWaitForDeletion = function() { - return _this.db.getRoleUsers('tester', function(err, obj) { - var _ref; - test.ok((_ref = _this.oUser.username, __indexOf.call(obj, _ref) < 0), 'User key still in role tester!'); - return _this.db.getUserRoles(_this.oUser.username, function(err, obj) { - test.ok(obj.length === 0, 'User still associated to roles!'); - return _this.db.getUserLinkedRules(_this.oUser.username, function(err, obj) { - test.ok(obj.length === 0, 'User still associated to rules!'); - return _this.db.getUserActivatedRules(_this.oUser.username, function(err, obj) { - test.ok(obj.length === 0, 'User still associated to activated rules!'); - return test.done(); - }); - }); - }); - }); - }; - _this.db.storeUser(_this.oUser); - _this.db.linkRule('rule-1', _this.oUser.username); - _this.db.linkRule('rule-2', _this.oUser.username); - _this.db.linkRule('rule-3', _this.oUser.username); - _this.db.activateRule('rule-1', _this.oUser.username); - _this.db.storeUserRole(_this.oUser.username, 'tester'); - return setTimeout(fWaitForPersistence, 100); - }, - testLogin: function(test) { - test.expect(3); - _this.db.storeUser(_this.oUser); - return _this.db.loginUser(_this.oUser.username, _this.oUser.password, function(err, obj) { - test.deepEqual(obj, _this.oUser, 'User not logged in!'); - return _this.db.loginUser('dummyname', _this.oUser.password, function(err, obj) { - test.strictEqual(obj, null, 'User logged in?!'); - return _this.db.loginUser(_this.oUser.username, 'wrongpass', function(err, obj) { - test.strictEqual(obj, null, 'User logged in?!'); - return test.done(); - }); - }); - }); - } - }; - - /* - # Test ROLES - */ - - - exports.Roles = { - setUp: function(cb) { - _this.db({ - logger: _this.log - }); - _this.oUser = { - username: "tester-1", - password: "password" - }; - return cb(); - }, - tearDown: function(cb) { - _this.db.deleteUser(_this.oUser.username); - return cb(); - }, - testStore: function(test) { - test.expect(2); - _this.db.storeUser(_this.oUser); - _this.db.storeUserRole(_this.oUser.username, 'tester'); - return _this.db.getUserRoles(_this.oUser.username, function(err, obj) { - test.ok(__indexOf.call(obj, 'tester') >= 0, 'User role tester not stored!'); - return _this.db.getRoleUsers('tester', function(err, obj) { - var _ref; - test.ok((_ref = _this.oUser.username, __indexOf.call(obj, _ref) >= 0), "User " + _this.oUser.username + " not stored in role tester!"); - return test.done(); - }); - }); - }, - testDelete: function(test) { - test.expect(2); - _this.db.storeUser(_this.oUser); - _this.db.storeUserRole(_this.oUser.username, 'tester'); - _this.db.removeUserRole(_this.oUser.username, 'tester'); - return _this.db.getUserRoles(_this.oUser.username, function(err, obj) { - test.ok(__indexOf.call(obj, 'tester') < 0, 'User role tester not stored!'); - return _this.db.getRoleUsers('tester', function(err, obj) { - var _ref; - test.ok((_ref = _this.oUser.username, __indexOf.call(obj, _ref) < 0), "User " + _this.oUser.username + " not stored in role tester!"); - return test.done(); - }); - }); - } - }; - -}).call(this); diff --git a/testing/old/mod_config.js b/testing/old/mod_config.js deleted file mode 100644 index 7d6ba5d..0000000 --- a/testing/old/mod_config.js +++ /dev/null @@ -1,270 +0,0 @@ - -exports.testUnit_DB = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// // # DB Interface -// // Handles the connection to the database and provides functionalities for -// // event/action modules, rules and the encrypted storing of authentication tokens. -// -// // ## General -// // General functionality as a wrapper for the module holds initialization, -// // encryption/decryption, the retrieval of modules and shut down. -// // Modules of the same group, e.g. action modules are registered in an unordered -// // set in the database, from where they can be retrieved again. For example a new -// // action module has its ID (e.g 'probinder') first registered in the set -// // 'action_modules' and then stored in the db with the key 'action\_module\_' + ID -// // (e.g. action\_module\_probinder). -// 'use strict'; -// var redis = require('redis'), - // crypto = require('crypto'), - // log = require('./logging'), - // crypto_key, db; -// -// -// // @function init() -// -// /* - // * Initializes the DB connection. Requires a port where the DB listens to requests - // * and a key that is used for encryptions. - // * @param {int} db_port - // */ -// exports.init = function(db_port, key, cbDone){ - // if(!db_port || !key) { - // log.error('DB', 'No DB port or cipher key defined!'); - // return null; - // } - // crypto_key = key; - // db = redis.createClient(db_port); - // db.on("error", function (err) { - // log.error('DB', ' Message from DB: ' + err); - // }); - // if(cbDone) cbDone(); -// }; -// -// /** - // * ### encrypt - // */ -// function encrypt(plainText) { - // if(!plainText) return null; - // try { - // var enciph = crypto.createCipher('aes-256-cbc', crypto_key); - // var et = enciph.update(plainText, 'utf8', 'base64') + enciph.final('base64'); - // log.print('DB', 'Encrypted credentials into: ' + et); - // return et; - // } catch (err) { - // log.error('DB', 'in encrypting: ' + err); - // return null; - // } -// } -// -// /** - // * ### decrypt - // */ -// function decrypt(crypticText) { - // if(!crypticText) return null; - // try { - // var deciph = crypto.createDecipher('aes-256-cbc', crypto_key); - // return deciph.update(crypticText, 'base64', 'utf8') + deciph.final('utf8'); - // } catch (err) { - // log.error('DB', 'in decrypting: ' + err); - // return null; - // } -// } -// -// /** - // * ### replyHandler - // * Abstraction answer handling for simple information replies from the DB. - // * @param {String} action the action to be displayed in the output string. - // */ -// function replyHandler(action) { - // return function(err, reply) { - // if(err) log.error('DB', ' during "' + action + '": ' + err); - // else log.print('DB', action + ': ' + reply); - // }; -// } -// -// /** - // * ### getSetRecords - // * The general structure for modules is that the key is stored in a set. - // * By fetching all set entries we can then fetch all modules, which is - // * automated in this function. - // * - // * @param {String} set the set name how it is stored in the DB - // * @param {function} funcSingle the function that fetches single entries from the DB - // * @param {function} callback the function to be called on success or error, receives - // * arguments (err, obj) - // */ -// function getSetRecords(set, funcSingle, callback) { - // db.smembers(set, function(err, reply) { - // if(err) log.error('DB', 'fetching ' + set + ': ' + err); - // else { - // if(reply.length === 0) { - // callback(null, null); - // } else { - // var semaphore = reply.length, objReplies = {}; - // setTimeout(function() { - // if(semaphore > 0) { - // callback('Timeout fetching ' + set, null); - // } - // }, 1000); - // for(var i = 0; i < reply.length; i++){ - // funcSingle(reply[i], function(prop) { - // return function(err, reply) { - // if(err) log.error('DB', ' fetching single element: ' + prop); - // else { - // objReplies[prop] = reply; - // if(--semaphore === 0) callback(null, objReplies); - // } - // }; - // }(reply[i])); - // } - // } - // } - // }); -// } -// -// // @method shutDown() -// -// // Shuts down the db link. -// exports.shutDown = function() { db.quit(); }; -// -// // ## Action Modules -// -// /** - // * ### storeActionModule - // * Store a string representation of an action module in the DB. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeActionModule = function(id, data) { - // db.sadd('action_modules', id, replyHandler('storing action module key ' + id)); - // db.set('action_module_' + id, data, replyHandler('storing action module ' + id)); -// }; -// -// /** - // * ### getActionModule(id, callback) - // * Query the DB for an action module. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModule = function(id, callback) { - // if(callback) db.get('action_module_' + id, callback); -// }; -// -// /** - // * ### getActionModules(callback) - // * Fetch all action modules. - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModules = function(callback) { - // getSetRecords('action_modules', exports.getActionModule, callback); -// }; -// -// /** - // * storeActionModuleAuth(id, data) - // * Store a string representation of the authentication parameters for an action module. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeActionModuleAuth = function(id, data) { - // if(data) { - // db.sadd('action_modules_auth', id, replyHandler('storing action module auth key ' + id)); - // db.set('action_module_' + id +'_auth', encrypt(data), replyHandler('storing action module auth ' + id)); - // } -// }; -// -// /** - // * ### getActionModuleAuth(id, callback) - // * Query the DB for an action module authentication token. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModuleAuth = function(id, callback) { - // if(callback) db.get('action_module_' + id + '_auth', function(err, txt) { callback(err, decrypt(txt)); }); -// }; -// -// // ## Event Modules -// -// /** - // * ### storeEventModule(id, data) - // * Store a string representation of an event module in the DB. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeEventModule = function(id, data) { - // db.sadd('event_modules', id, replyHandler('storing event module key ' + id)); - // db.set('event_module_' + id, data, replyHandler('storing event module ' + id)); -// }; -// -// /** - // * ### getEventModule(id, callback) - // * Query the DB for an event module. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getEventModule = function(id, callback) { - // if(callback) db.get('event_module_' + id, callback); -// }; -// -// /** - // * ### getEventModules(callback) - // * Fetch all event modules. - // * @param {function} callback the callback that receives the arguments (err, obj) - // */ -// exports.getEventModules = function(callback) { - // getSetRecords('event_modules', exports.getEventModule, callback); -// }; -// -// /** - // * ### storeEventModuleAuth(id, data) - // * Store a string representation of he authentication parameters for an event module. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeEventModuleAuth = function(id, data) { - // if(data) { - // db.sadd('event_modules_auth', id, replyHandler('storing event module auth key ' + id)); - // db.set('event_module_' + id +'_auth', encrypt(data), replyHandler('storing event module auth ' + id)); - // } -// }; -// -// // @method getEventModuleAuth(id, callback) -// -// // Query the DB for an event module authentication token. -// // @param {String} id the module id -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getEventModuleAuth = function(id, callback) { - // if(callback) db.get('event_module_' + id +'_auth', function(err, txt) { callback(err, decrypt(txt)); }); -// }; -// -// // ## Rules -// -// // @method storeRule(id, data) -// -// // Store a string representation of a rule in the DB. -// // @param {String} id the unique identifier of the rule -// // @param {String} data the string representation -// exports.storeRule = function(id, data) { - // db.sadd('rules', id, replyHandler('storing rule key ' + id)); - // db.set('rule_' + id, data, replyHandler('storing rule ' + id)); -// }; -// -// // @method getRule(id, callback) -// -// // Query the DB for a rule. -// // @param {String} id the rule id -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getRule = function(id, callback) { - // db.get('rule_' + id, callback); -// }; -// -// // @method getRules(callback) -// -// // Fetch all rules from the database. -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getRules = function(callback) { - // getSetRecords('rules', exports.getRule, callback); -// }; -// diff --git a/testing/old/mod_db_interface.js b/testing/old/mod_db_interface.js deleted file mode 100644 index 7d6ba5d..0000000 --- a/testing/old/mod_db_interface.js +++ /dev/null @@ -1,270 +0,0 @@ - -exports.testUnit_DB = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// // # DB Interface -// // Handles the connection to the database and provides functionalities for -// // event/action modules, rules and the encrypted storing of authentication tokens. -// -// // ## General -// // General functionality as a wrapper for the module holds initialization, -// // encryption/decryption, the retrieval of modules and shut down. -// // Modules of the same group, e.g. action modules are registered in an unordered -// // set in the database, from where they can be retrieved again. For example a new -// // action module has its ID (e.g 'probinder') first registered in the set -// // 'action_modules' and then stored in the db with the key 'action\_module\_' + ID -// // (e.g. action\_module\_probinder). -// 'use strict'; -// var redis = require('redis'), - // crypto = require('crypto'), - // log = require('./logging'), - // crypto_key, db; -// -// -// // @function init() -// -// /* - // * Initializes the DB connection. Requires a port where the DB listens to requests - // * and a key that is used for encryptions. - // * @param {int} db_port - // */ -// exports.init = function(db_port, key, cbDone){ - // if(!db_port || !key) { - // log.error('DB', 'No DB port or cipher key defined!'); - // return null; - // } - // crypto_key = key; - // db = redis.createClient(db_port); - // db.on("error", function (err) { - // log.error('DB', ' Message from DB: ' + err); - // }); - // if(cbDone) cbDone(); -// }; -// -// /** - // * ### encrypt - // */ -// function encrypt(plainText) { - // if(!plainText) return null; - // try { - // var enciph = crypto.createCipher('aes-256-cbc', crypto_key); - // var et = enciph.update(plainText, 'utf8', 'base64') + enciph.final('base64'); - // log.print('DB', 'Encrypted credentials into: ' + et); - // return et; - // } catch (err) { - // log.error('DB', 'in encrypting: ' + err); - // return null; - // } -// } -// -// /** - // * ### decrypt - // */ -// function decrypt(crypticText) { - // if(!crypticText) return null; - // try { - // var deciph = crypto.createDecipher('aes-256-cbc', crypto_key); - // return deciph.update(crypticText, 'base64', 'utf8') + deciph.final('utf8'); - // } catch (err) { - // log.error('DB', 'in decrypting: ' + err); - // return null; - // } -// } -// -// /** - // * ### replyHandler - // * Abstraction answer handling for simple information replies from the DB. - // * @param {String} action the action to be displayed in the output string. - // */ -// function replyHandler(action) { - // return function(err, reply) { - // if(err) log.error('DB', ' during "' + action + '": ' + err); - // else log.print('DB', action + ': ' + reply); - // }; -// } -// -// /** - // * ### getSetRecords - // * The general structure for modules is that the key is stored in a set. - // * By fetching all set entries we can then fetch all modules, which is - // * automated in this function. - // * - // * @param {String} set the set name how it is stored in the DB - // * @param {function} funcSingle the function that fetches single entries from the DB - // * @param {function} callback the function to be called on success or error, receives - // * arguments (err, obj) - // */ -// function getSetRecords(set, funcSingle, callback) { - // db.smembers(set, function(err, reply) { - // if(err) log.error('DB', 'fetching ' + set + ': ' + err); - // else { - // if(reply.length === 0) { - // callback(null, null); - // } else { - // var semaphore = reply.length, objReplies = {}; - // setTimeout(function() { - // if(semaphore > 0) { - // callback('Timeout fetching ' + set, null); - // } - // }, 1000); - // for(var i = 0; i < reply.length; i++){ - // funcSingle(reply[i], function(prop) { - // return function(err, reply) { - // if(err) log.error('DB', ' fetching single element: ' + prop); - // else { - // objReplies[prop] = reply; - // if(--semaphore === 0) callback(null, objReplies); - // } - // }; - // }(reply[i])); - // } - // } - // } - // }); -// } -// -// // @method shutDown() -// -// // Shuts down the db link. -// exports.shutDown = function() { db.quit(); }; -// -// // ## Action Modules -// -// /** - // * ### storeActionModule - // * Store a string representation of an action module in the DB. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeActionModule = function(id, data) { - // db.sadd('action_modules', id, replyHandler('storing action module key ' + id)); - // db.set('action_module_' + id, data, replyHandler('storing action module ' + id)); -// }; -// -// /** - // * ### getActionModule(id, callback) - // * Query the DB for an action module. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModule = function(id, callback) { - // if(callback) db.get('action_module_' + id, callback); -// }; -// -// /** - // * ### getActionModules(callback) - // * Fetch all action modules. - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModules = function(callback) { - // getSetRecords('action_modules', exports.getActionModule, callback); -// }; -// -// /** - // * storeActionModuleAuth(id, data) - // * Store a string representation of the authentication parameters for an action module. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeActionModuleAuth = function(id, data) { - // if(data) { - // db.sadd('action_modules_auth', id, replyHandler('storing action module auth key ' + id)); - // db.set('action_module_' + id +'_auth', encrypt(data), replyHandler('storing action module auth ' + id)); - // } -// }; -// -// /** - // * ### getActionModuleAuth(id, callback) - // * Query the DB for an action module authentication token. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getActionModuleAuth = function(id, callback) { - // if(callback) db.get('action_module_' + id + '_auth', function(err, txt) { callback(err, decrypt(txt)); }); -// }; -// -// // ## Event Modules -// -// /** - // * ### storeEventModule(id, data) - // * Store a string representation of an event module in the DB. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeEventModule = function(id, data) { - // db.sadd('event_modules', id, replyHandler('storing event module key ' + id)); - // db.set('event_module_' + id, data, replyHandler('storing event module ' + id)); -// }; -// -// /** - // * ### getEventModule(id, callback) - // * Query the DB for an event module. - // * @param {String} id the module id - // * @param {function} callback the callback to receive the answer (err, obj) - // */ -// exports.getEventModule = function(id, callback) { - // if(callback) db.get('event_module_' + id, callback); -// }; -// -// /** - // * ### getEventModules(callback) - // * Fetch all event modules. - // * @param {function} callback the callback that receives the arguments (err, obj) - // */ -// exports.getEventModules = function(callback) { - // getSetRecords('event_modules', exports.getEventModule, callback); -// }; -// -// /** - // * ### storeEventModuleAuth(id, data) - // * Store a string representation of he authentication parameters for an event module. - // * @param {String} id the unique identifier of the module - // * @param {String} data the string representation - // */ -// exports.storeEventModuleAuth = function(id, data) { - // if(data) { - // db.sadd('event_modules_auth', id, replyHandler('storing event module auth key ' + id)); - // db.set('event_module_' + id +'_auth', encrypt(data), replyHandler('storing event module auth ' + id)); - // } -// }; -// -// // @method getEventModuleAuth(id, callback) -// -// // Query the DB for an event module authentication token. -// // @param {String} id the module id -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getEventModuleAuth = function(id, callback) { - // if(callback) db.get('event_module_' + id +'_auth', function(err, txt) { callback(err, decrypt(txt)); }); -// }; -// -// // ## Rules -// -// // @method storeRule(id, data) -// -// // Store a string representation of a rule in the DB. -// // @param {String} id the unique identifier of the rule -// // @param {String} data the string representation -// exports.storeRule = function(id, data) { - // db.sadd('rules', id, replyHandler('storing rule key ' + id)); - // db.set('rule_' + id, data, replyHandler('storing rule ' + id)); -// }; -// -// // @method getRule(id, callback) -// -// // Query the DB for a rule. -// // @param {String} id the rule id -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getRule = function(id, callback) { - // db.get('rule_' + id, callback); -// }; -// -// // @method getRules(callback) -// -// // Fetch all rules from the database. -// // @param {function} callback the callback to receive the answer (err, obj) -// exports.getRules = function(callback) { - // getSetRecords('rules', exports.getRule, callback); -// }; -// diff --git a/testing/old/mod_engine.js b/testing/old/mod_engine.js deleted file mode 100644 index d903943..0000000 --- a/testing/old/mod_engine.js +++ /dev/null @@ -1,282 +0,0 @@ - - exports.setUp = function (callback) { - console.log('setup in module'); - callback(); - }; -exports.testUnit_ENG = function(test){ - test.ok(true, "ENG"); - test.done(); -}; - -exports.group = { - setUp: function (callback) { - console.log('setup in group'); - callback(); - }, - test2: function (test) { - test.ok(true, "ENG"); - test.done(); - }, - test3: function (test) { - test.ok(true, "ENG"); - test.done(); - } -}; - -exports.testUnit_Engine = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - - -// 'use strict'; -// -// var cp = require('child_process'), ml = require('./module_loader'), - // log = require('./logging'), - // poller, db, isRunning = true, - // qEvents = new (require('./queue')).Queue(); // export queue into redis -// -// var regex = /\$X\.[\w\.\[\]]*/g, // find properties of $X - // listRules = {}, - // listActionModules = {}, - // actionsLoaded = false, eventsLoaded = false; -// /* - // * Initialize the rules engine which initializes the module loader. - // * @param {Object} db_link the link to the db, see [db\_interface](db_interface.html) - // * @param {String} db_port the db port - // * @param {String} crypto_key the key to be used for encryption on the db, max legnth 256 - // */ -// function init(db_link, db_port, crypto_key) { - // db = db_link; - // loadActions(); - // poller = cp.fork('./eventpoller', [db_port, crypto_key]); - // poller.on('message', function(evt) { - // if(evt.event === 'ep_finished_loading') { - // eventsLoaded = true; - // tryToLoadRules(); - // } else pushEvent(evt); - // }); - // //start to poll the event queue - // pollQueue(); -// } -// -// function loadActions() { - // db.getActionModules(function(err, obj) { - // if(err) log.error('EN', 'retrieving Action Modules from DB!'); - // else { - // if(!obj) { - // log.print('EN', 'No Action Modules found in DB!'); - // actionsLoaded = true; - // tryToLoadRules(); - // } else { - // var m, semaphore = 0; - // for(var el in obj) { - // semaphore++; - // log.print('EN', 'Loading Action Module from DB: ' + el); - // m = ml.requireFromString(obj[el], el); - // db.getActionModuleAuth(el, function(mod) { - // return function(err, obj) { - // if(--semaphore == 0) { - // actionsLoaded = true; - // tryToLoadRules(); - // } - // if(obj && mod.loadCredentials) mod.loadCredentials(JSON.parse(obj)); - // }; - // }(m)); - // listActionModules[el] = m; - // } - // } - // } - // }); -// } -// -// function tryToLoadRules() { - // if(eventsLoaded && actionsLoaded) { - // db.getRules(function(err, obj) { - // for(var el in obj) loadRule(JSON.parse(obj[el])); - // }); - // } -// } -// -// /** - // * Insert an action module into the list of available interfaces. - // * @param {Object} objModule the action module object - // */ -// function loadActionModule(name, objModule) { - // log.print('EN', 'Action module "' + name + '" loaded'); - // listActionModules[name] = objModule; -// } -// -// /** - // * Insert a rule into the eca rules repository - // * @param {Object} objRule the rule object - // */ -// function loadRule(objRule) { - // //TODO validate rule - // log.print('EN', 'Loading Rule: ' + objRule.id); - // if(listRules[objRule.id]) log.print('EN', 'Replacing rule: ' + objRule.id); - // listRules[objRule.id] = objRule; -// - // // Notify poller about eventual candidate - // try { - // poller.send('event|'+objRule.event); - // } catch (err) { - // log.print('EN', 'Unable to inform poller about new active rule!'); - // } -// } -// -// function pollQueue() { - // if(isRunning) { - // var evt = qEvents.dequeue(); - // if(evt) { - // processEvent(evt); - // } - // setTimeout(pollQueue, 50); //TODO adapt to load - // } -// } -// -// /** - // * Stores correctly posted events in the queue - // * @param {Object} evt The event object - // */ -// function pushEvent(evt) { - // qEvents.enqueue(evt); -// } -// -// /** - // * Handles correctly posted events - // * @param {Object} evt The event object - // */ -// function processEvent(evt) { - // log.print('EN', 'processing event: ' + evt.event + '(' + evt.eventid + ')'); - // var actions = checkEvent(evt); - // for(var i = 0; i < actions.length; i++) { - // invokeAction(evt, actions[i]); - // } -// } -// -// /** - // * Check an event against the rules repository and return the actions - // * if the conditons are met. - // * @param {Object} evt the event to check - // */ -// function checkEvent(evt) { - // var actions = []; - // for(var rn in listRules) { - // //TODO this needs to get depth safe, not only data but eventually also - // // on one level above (eventid and other meta) - // if(listRules[rn].event === evt.event && validConditions(evt.data, listRules[rn])) { - // log.print('EN', 'Rule "' + rn + '" fired'); - // actions = actions.concat(listRules[rn].actions); - // } - // } - // return actions; -// } -// -// /** - // * Checks whether all conditions of the rule are met by the event. - // * @param {Object} evt the event to check - // * @param {Object} rule the rule with its conditions - // */ -// function validConditions(evt, rule) { - // for(var property in rule.condition){ - // if(!evt[property] || evt[property] != rule.condition[property]) return false; - // } - // return true; -// } -// -// /** - // * Invoke an action according to its type. - // * @param {Object} evt The event that invoked the action - // * @param {Object} action The action to be invoked - // */ -// function invokeAction(evt, action) { - // var actionargs = {}, - // arrModule = action.module.split('->'); - // if(arrModule.length < 2) { - // log.error('EN', 'Invalid rule detected!'); - // return; - // } - // var srvc = listActionModules[arrModule[0]]; - // if(srvc && srvc[arrModule[1]]) { - // //FIXME preprocessing not only on data - // preprocessActionArguments(evt.data, action.arguments, actionargs); - // try { - // if(srvc[arrModule[1]]) srvc[arrModule[1]](actionargs); - // } catch(err) { - // log.error('EN', 'during action execution: ' + err); - // } - // } - // else log.print('EN', 'No api interface found for: ' + action.module); -// } -// -// /** - // * Action properties may contain event properties which need to be resolved beforehand. - // * @param {Object} evt The event whose property values can be used in the rules action - // * @param {Object} act The rules action arguments - // * @param {Object} res The object to be used to enter the new properties - // */ -// function preprocessActionArguments(evt, act, res) { - // for(var prop in act) { - // /* - // * If the property is an object itself we go into recursion - // */ - // if(typeof act[prop] === 'object') { - // res[prop] = {}; - // preprocessActionArguments(evt, act[prop], res[prop]); - // } - // else { - // var txt = act[prop]; - // var arr = txt.match(regex); - // /* - // * If rules action property holds event properties we resolve them and - // * replace the original action property - // */ - // // console.log(evt); - // if(arr) { - // for(var i = 0; i < arr.length; i++) { - // /* - // * The first three characters are '$X.', followed by the property - // */ - // var actionProp = arr[i].substring(3).toLowerCase(); - // // console.log(actionProp); - // for(var eprop in evt) { - // // our rules language doesn't care about upper or lower case - // if(eprop.toLowerCase() === actionProp) { - // txt = txt.replace(arr[i], evt[eprop]); - // } - // } - // txt = txt.replace(arr[i], '[property not available]'); - // } - // } - // res[prop] = txt; - // } - // } -// } -// -// function loadEventModule(args, answHandler) { - // if(args && args.name) { - // answHandler.answerSuccess('Loading event module ' + args.name + '...'); - // poller.send('cmd|loadevent|'+args.name); - // } else if(args) answHandler.answerError(args.name + ' not found'); -// } -// -// function loadEventModules(args, answHandler) { - // answHandler.answerSuccess('Loading event moules...'); - // poller.send('cmd|loadevents'); -// } -// -// function shutDown() { - // log.print('EN', 'Shutting down Poller and DB Link'); - // isRunning = false; - // poller.send('cmd|shutdown'); - // db.shutDown(); -// } -// -// exports.init = init; -// exports.loadActionModule = loadActionModule; -// exports.loadRule = loadRule; -// exports.loadEventModule = loadEventModule; -// exports.loadEventModules = loadEventModules; -// exports.pushEvent = pushEvent; -// exports.shutDown = shutDown; diff --git a/testing/old/mod_eventpoller.js b/testing/old/mod_eventpoller.js deleted file mode 100644 index 350dfa8..0000000 --- a/testing/old/mod_eventpoller.js +++ /dev/null @@ -1,144 +0,0 @@ - -exports.testUnit_EventPoller = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// // # Event Poller -// -// 'use strict'; -// -// if(process.argv.length < 3) { - // log.error('EP', 'No DB port defined! Not starting poller...'); -// } else { - // (function() { - // var fs = require('fs'), - // path = require('path'), - // log = require('./logging'), - // db = require('./db_interface'), - // ml = require('./module_loader'), - // listMessageActions = {}, - // listAdminCommands = {}, - // listEventModules = {}, - // listPoll = {}, //TODO this will change in the future because it could have - // //several parameterized (user-specific) instances of each event module - // isRunning = true, - // eId = 0; - // //TODO allow different polling intervals (a wrapper together with settimeout per to be polled could be an easy and solution) -// - // db.init(process.argv[2], process.argv[3]); -// - // //TODO eventpoller will not load event modules from filesystem, this will be done by - // // the moduel manager and the eventpoller receives messages about new/updated active rules -// - // db.getEventModules(function(err, obj) { - // if(err) log.error('EP', 'retrieving Event Modules from DB!'); - // else { - // if(!obj) { - // log.print('EP', 'No Event Modules found in DB!'); - // process.send({ event: 'ep_finished_loading' }); - // } else { - // var m, semaphore = 0; - // for(var el in obj) { - // semaphore++; - // m = ml.requireFromString(obj[el], el); - // db.getEventModuleAuth(el, function(mod) { - // return function(err, obj) { - // if(--semaphore === 0) process.send({ event: 'ep_finished_loading' }); - // if(obj && mod.loadCredentials) mod.loadCredentials(JSON.parse(obj)); - // }; - // }(m)); - // log.print('EP', 'Loading Event Module: ' + el); - // listEventModules[el] = m; - // } - // } - // } - // }); -// - // listMessageActions['event'] = function(args) { - // var prop = args[1], arrModule = prop.split('->'); - // // var arrModule = obj.module.split('->'); - // if(arrModule.length > 1){ - // var module = listEventModules[arrModule[0]]; - // for(var i = 1; i < arrModule.length; i++) { - // if(module) module = module[arrModule[i]]; - // } - // if(module) { - // log.print('EP', 'Found active event module "' + prop + '", adding it to polling list'); - // listPoll[prop] = module; - // } else { - // log.print('EP', 'No property "' + prop + '" found'); - // } - // } - // }; -// - // listAdminCommands['loadevent'] = function(args) { - // ml.loadModule('mod_events', args[2], loadEventCallback); - // }; -// - // listAdminCommands['loadevents'] = function(args) { - // ml.loadModules('mod_events', loadEventCallback); - // }; -// - // listAdminCommands['shutdown'] = function(args) { - // log.print('EP', 'Shutting down DB Link'); - // isRunning = false; - // db.shutDown(); - // }; -// - // //TODO this goes into module_manager, this will receive notification about - // // new loaded/stored event modules and fetch them from the db - // listMessageActions['cmd'] = function(args) { - // var func = listAdminCommands[args[1]]; - // if(typeof(func) === 'function') func(args); - // }; -// - // process.on('message', function(strProps) { - // var arrProps = strProps.split('|'); - // if(arrProps.length < 2) log.error('EP', 'too few parameter in message!'); - // else { - // var func = listMessageActions[arrProps[0]]; - // if(func) func(arrProps); - // } - // }); - // function loadEventCallback(name, data, mod, auth) { - // db.storeEventModule(name, data); // store module in db - // if(auth) db.storeEventModuleAuth(name, auth); - // listEventModules[name] = mod; // store compiled module for polling - // } -// - // function checkRemotes() { - // var txt = 'Polled active event modules: '; - // for(var prop in listPoll) { - // txt += prop + ', '; - // listPoll[prop]( - // /* - // * what a hack to get prop local :-P - // * define and immediately call anonymous function with param prop. - // * This places the value of prop into the context of the callback - // * and thus doesn't change when the for loop keeps iterating over listPoll - // */ - // (function(p) { - // return function(obj) { - // process.send({ - // event: p, - // eventid: 'polled_' + eId++, - // data: obj - // }); - // }; - // })(prop) - // ); - // } - // log.print('EP', txt); - // } -// - // function pollLoop() { - // if(isRunning) { - // checkRemotes(); - // setTimeout(pollLoop, 10000); - // } - // } -// - // pollLoop(); - // })(); -// } \ No newline at end of file diff --git a/testing/old/mod_http_listener.js b/testing/old/mod_http_listener.js deleted file mode 100644 index 11f48bf..0000000 --- a/testing/old/mod_http_listener.js +++ /dev/null @@ -1,110 +0,0 @@ - -exports.testUnit_HL = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// // # HTTP Listener -// // Isso -// 'use strict'; -// var express = require('express'), - // port = express(), - // log = require('./logging'), - // qs = require('querystring'), - // adminHandler, eventHandler, server; -// -// function init(http_port, funcAdminHandler, funcEvtHandler) { - // if(!http_port || !funcEvtHandler) { - // log.error('HL', 'ERROR: either port or eventHandler function not defined!'); - // return; - // } - // adminHandler = funcAdminHandler; - // eventHandler = funcEvtHandler; - // // port.get('/doc*', onDocRequest); - // port.use('/doc', express.static(__dirname + '/../doc')); - // port.use('/doc', express.static(__dirname + '/../doc-na')); - // port.get('/admin', onAdminCommand); - // port.post('/pushEvents', onPushEvent); - // server = port.listen(http_port); // inbound event channel - // log.print('HL', 'Started listening for http requests on port ' + http_port); -// } -// -// function answerHandler(r) { - // var response = r, hasBeenAnswered = false; - // function postAnswer(msg) { - // if(!hasBeenAnswered) { - // response.write(msg); - // response.end(); - // hasBeenAnswered = true; - // } - // } - // return { - // answerSuccess: function(msg) { - // if(!hasBeenAnswered) response.writeHead(200, { "Content-Type": "text/plain" }); - // postAnswer(msg); - // }, - // answerError: function(msg) { - // if(!hasBeenAnswered) response.writeHead(400, { "Content-Type": "text/plain" }); - // postAnswer(msg); - // }, - // isAnswered: function() { return hasBeenAnswered; } - // }; -// }; -// -// // function onDocRequest(request, response) { - // // var pth = request.url; - // // pth = pth.substring(4); - // // if(pth.substring(pth.length-1) === '/') pth += 'index.html'; - // // console.log(pth); -// // } -// -// /** - // * Handles correct event posts, replies thank you. - // */ -// function answerSuccess(resp, msg){ - // resp.writeHead(200, { "Content-Type": "text/plain" }); - // resp.write(msg); - // resp.end(); -// } -// -// /** - // * Handles erroneous requests. - // * @param {Object} msg the error message to be returned - // */ -// function answerError(resp, msg) { - // resp.writeHead(400, { "Content-Type": "text/plain" }); - // resp.write(msg); - // resp.end(); -// } -// -// //FIXME this answer handling is a very ugly hack, improve! -// function onAdminCommand(request, response) { - // var q = request.query; - // log.print('HL', 'Received admin request: ' + request.originalUrl); - // if(q.cmd) { - // adminHandler(q, answerHandler(response)); - // // answerSuccess(response, 'Thank you, we try our best!'); - // } else answerError(response, 'I\'m not sure about what you want from me...'); -// } -// -// /** - // * If a request is made to the server, this function is used to handle it. - // */ -// function onPushEvent(request, response) { - // var body = ''; - // request.on('data', function (data) { body += data; }); - // request.on('end', function () { - // var obj = qs.parse(body); - // /* If required event properties are present we process the event */ - // if(obj && obj.event && obj.eventid){ - // answerSuccess(response, 'Thank you for the event (' + obj.event + '[' + obj.eventid + '])!'); - // eventHandler(obj); - // } else answerError(response, 'Your event was missing important parameters!'); - // }); -// } -// -// exports.init = init; -// exports.shutDown = function() { - // log.print('HL', 'Shutting down HTTP listener'); - // process.exit(); // This is a bit brute force... -// }; diff --git a/testing/old/mod_logging.js b/testing/old/mod_logging.js deleted file mode 100644 index 13919fc..0000000 --- a/testing/old/mod_logging.js +++ /dev/null @@ -1,32 +0,0 @@ - -exports.testUnit_LOG = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// /* - // * # Logging - // * Functions to funnel logging - // */ -// -// // @function print(module, msg) -// -// /* - // * Prints a log to stdout. - // * @param {String} module - // * @param {String} msg - // */ -// exports.print = function(module, msg) { - // console.log((new Date()).toISOString() + ' | ' + module + ' | ' + msg); -// }; -// -// // @function error(module, msg) -// -// /* - // * Prints a log to stderr. - // * @param {String} module - // * @param {String} msg - // */ -// exports.error = function(module, msg) { - // console.error((new Date()).toISOString() + ' | ' + module + ' | ERROR: ' + msg); -// }; diff --git a/testing/old/mod_module_loader.js b/testing/old/mod_module_loader.js deleted file mode 100644 index 2793d87..0000000 --- a/testing/old/mod_module_loader.js +++ /dev/null @@ -1,74 +0,0 @@ - -exports.testUnit_ML = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// var fs = require('fs'), - // path = require('path'), - // log = require('./logging'); -// -// function requireFromString(src, name, dir) { - // if(!dir) dir = __dirname; - // // YAH yet another hack, this time to load modules from strings - // var id = path.resolve(dir, name, name + '.js'); - // var m = new module.constructor(id, module); - // m.paths = module.paths; - // try { - // m._compile(src); - // } catch(err) { - // log.error('LM', ' during compilation of ' + name + ': ' + err); - // } - // return m.exports; -// } -// -// function loadModule(directory, name, callback) { - // //FIXME contextualize and only allow small set of modules for safety reasons - // try { - // fs.readFile(path.resolve(directory, name, name + '.js'), 'utf8', function (err, data) { - // if (err) { - // log.error('LM', 'Loading module file!'); - // return; - // } - // var mod = requireFromString(data, name, directory); - // if(mod && fs.existsSync(path.resolve(directory, name, 'credentials.json'))) { - // fs.readFile(path.resolve(directory, name, 'credentials.json'), 'utf8', function (err, auth) { - // if (err) { - // log.error('LM', 'Loading credentials file for "' + name + '"!'); - // callback(name, data, mod, null); - // return; - // } - // if(mod.loadCredentials) mod.loadCredentials(JSON.parse(auth)); - // callback(name, data, mod, auth); - // }); - // } else { - // // Hand back the name, the string contents and the compiled module - // callback(name, data, mod, null); - // } - // }); - // } catch(err) { - // log.error('LM', 'Failed loading module "' + name + '"'); - // } -// } -// -// function loadModules(directory, callback) { - // fs.readdir(path.resolve(__dirname, directory), function (err, list) { - // if (err) { - // log.error('LM', 'loading modules directory: ' + err); - // return; - // } - // log.print('LM', 'Loading ' + list.length + ' modules from "' + directory + '"'); - // list.forEach(function (file) { - // fs.stat(path.resolve(__dirname, directory, file), function (err, stat) { - // if (stat && stat.isDirectory()) { - // loadModule(path.resolve(__dirname, directory), file, callback); - // } - // }); - // }); - // }); -// } -// -// exports.loadModule = loadModule; -// exports.loadModules = loadModules; -// exports.requireFromString = requireFromString; -// diff --git a/testing/old/mod_module_manager.js b/testing/old/mod_module_manager.js deleted file mode 100644 index 1dc5eb9..0000000 --- a/testing/old/mod_module_manager.js +++ /dev/null @@ -1,103 +0,0 @@ - -exports.testUnit_MM = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; - -// /* -// # Module Manager -// > The module manager takes care of the module and rules loading in the initialization -// > phase and on user request. -// -// > Event and Action modules are loaded as strings and stored in the database, -// > then compiled into node modules and and rules - // */ -// var fs = require('fs'), - // path = require('path'), - // log = require('./logging'), - // ml = require('./module_loader'), - // db = null, funcLoadAction, funcLoadRule; -// -// function init(db_link, fLoadAction, fLoadRule) { - // db = db_link; - // funcLoadAction = fLoadAction; - // funcLoadRule = fLoadRule; -// } -// /* -// # A First Level Header -// -// -// A Second Level Header -// --------------------- -// -// Now is the time for all good men to come to -// the aid of their country. This is just a -// regular paragraph. -// -// The quick brown fox jumped over the lazy -// dog's back. -// -// ### Header 3 -// -// > This is a blockquote. -// > -// > This is the second paragraph in the blockquote. -// > -// > ## This is an H2 in a blockquote -// -// This is the function documentation -// @param {Object} [args] the optional arguments -// @param {String} [args.name] the optional name in the arguments - // */ -// function loadRulesFile(args, answHandler) { - // //FIXME if a corrupt rule file is read the system crashes, prevent this also for event and action modules - // if(!args) args = {}; - // if(!args.name) args.name = 'rules'; - // if(!funcLoadRule) log.error('ML', 'no rule loader function available'); - // else { - // fs.readFile(path.resolve(__dirname, 'rules', args.name + '.json'), 'utf8', function (err, data) { - // if (err) { - // log.error('ML', 'Loading rules file: ' + args.name + '.json'); - // return; - // } - // var arr = JSON.parse(data), txt = ''; - // log.print('ML', 'Loading ' + arr.length + ' rules:'); - // for(var i = 0; i < arr.length; i++) { - // txt += arr[i].id + ', '; - // db.storeRule(arr[i].id, JSON.stringify(arr[i])); - // funcLoadRule(arr[i]); - // } - // answHandler.answerSuccess('Yep, loaded rules: ' + txt); - // }); - // } -// } -// -// /** - // * - // * @param {Object} name - // * @param {Object} data - // * @param {Object} mod - // * @param {String} [auth] The string representation of the auth json - // */ -// function loadActionCallback(name, data, mod, auth) { - // db.storeActionModule(name, data); // store module in db - // funcLoadAction(name, mod); // hand compiled module back - // if(auth) db.storeActionModuleAuth(name, auth); -// } -// -// function loadActionModule(args, answHandler) { - // if(args && args.name) { - // answHandler.answerSuccess('Loading action module ' + args.name + '...'); - // ml.loadModule('mod_actions', args.name, loadActionCallback); - // } -// } -// -// function loadActionModules(args, answHandler) { - // answHandler.answerSuccess('Loading action modules...'); - // ml.loadModules('mod_actions', loadActionCallback); -// } -// -// exports.init = init; -// exports.loadRulesFile = loadRulesFile; -// exports.loadActionModule = loadActionModule; -// exports.loadActionModules = loadActionModules; \ No newline at end of file diff --git a/testing/old/mod_server.js b/testing/old/mod_server.js deleted file mode 100644 index e03e13a..0000000 --- a/testing/old/mod_server.js +++ /dev/null @@ -1,81 +0,0 @@ -var path = require('path'); -//FIXME handle EADDR in use! -exports.setUp = function(cb) { - this.srv = require('child_process').fork(path.resolve(__dirname, '..', 'js', 'server'), ['2']); - cb(); -}; - -exports.testUnit_SRV = function(test){ - test.ok(false, "needs implementation"); - setTimeout( - function() { - - test.ok(true, "SRV"); - test.done(); - } - , 2000); -}; -exports.tearDown = function(cb) { - console.log('this.srv: '); - // console.log(global.srv); - this.srv.send('die'); - this.srv = null; - cb(); -}; - -// var http_listener = require('./http_listener'), - // db = require('./db_interface'), - // engine = require('./engine'), - // mm = require('./module_manager'), - // log = require('./logging'), - // fs = require('fs'), - // path = require('path'), - // objCmds = { - // 'loadrules': mm.loadRulesFile, - // 'loadaction': mm.loadActionModule, - // 'loadactions': mm.loadActionModules, - // 'loadevent': engine.loadEventModule, - // 'loadevents': engine.loadEventModules, - // 'shutdown': shutDown, - // 'restart': null //TODO implement - // }; -// -// function handleAdminCommands(args, answHandler) { - // if(args && args.cmd) { - // var func = objCmds[args.cmd]; - // if(func) func(args, answHandler); - // } else log.print('RS', 'No command in request'); - // setTimeout(function(ah) { - // answHandler = ah; - // return function() { - // if(!answHandler.isAnswered()) answHandler.answerError('Not handeled...'); - // }; - // }, 2000); -// } -// -// function shutDown(args, answHandler) { - // answHandler.answerSuccess('Goodbye!'); - // log.print('RS', 'Received shut down command!'); - // engine.shutDown(); - // http_listener.shutDown(); -// } -// -// fs.readFile(path.resolve(__dirname, 'config', 'config.json'), 'utf8', function (err, data) { - // if (err) { - // log.error('RS', 'Loading config file'); - // return; - // } - // var config = JSON.parse(data); - // if(!config.http_port || !config.db_port || !config.crypto_key) { - // log.error('RS', 'you forgot to define either http_port, db_port, crypto_key, or even all of them!'); - // } else { - // log.print('RS', 'Initialzing DB'); - // db.init(config.db_port, config.crypto_key, function() { - // engine.init(db, config.db_port, config.crypto_key); - // }); - // log.print('RS', 'Initialzing http listener'); - // http_listener.init(config.http_port, handleAdminCommands, engine.pushEvent); - // log.print('RS', 'Initialzing module manager'); - // mm.init(db, engine.loadActionModule, engine.loadRule); - // } -// }); \ No newline at end of file diff --git a/testing/old/mod_user.js b/testing/old/mod_user.js deleted file mode 100644 index 5123694..0000000 --- a/testing/old/mod_user.js +++ /dev/null @@ -1,9 +0,0 @@ - -exports.setUp = function() { - this.mod = require('./user'); -}; - -exports.addUser = function() { - test.ok(false, "needs implementation"); - -}; diff --git a/testing/old/unit_integration.js b/testing/old/unit_integration.js deleted file mode 100644 index c18b28d..0000000 --- a/testing/old/unit_integration.js +++ /dev/null @@ -1,7 +0,0 @@ - -exports.testUnitIntegration = function(test){ - test.ok(false, "needs implementation"); - test.done(); -}; -//TODO malicious module has to be loaded only for testing, the error -// it causes need to be verified and in the end the module need to be deleted again \ No newline at end of file diff --git a/testing/old/whole_system.js b/testing/old/whole_system.js deleted file mode 100644 index 175e420..0000000 --- a/testing/old/whole_system.js +++ /dev/null @@ -1,18 +0,0 @@ -var path = require('path'); -//FIXME handle EADDR in use! -exports.setUp = function(cb) { - this.srv = require('child_process').fork(path.resolve(__dirname, '..', 'js', 'server'), ['2']); - cb(); -}; - -exports.testSystem = function(test){ - - test.ok(false, "needs implementation"); - test.done(); -}; - -exports.tearDown = function(cb) { - this.srv.send('die'); - this.srv = null; - cb(); -}; \ No newline at end of file