Permalink
Browse files

ready to merge

  • Loading branch information...
hochang committed Feb 14, 2013
1 parent 03c7afe commit d56e432920108b170f53e47c303276188970b73c
@@ -1,22 +1,24 @@
+/*
+ * Code taken from Danne Lundqvist with custom modification
+ * http://www.dotvoid.com/2005/06/aspect-oriented-programming-and-javascript/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
var InvalidAspect = new Error("Missing a valid aspect. Aspect is not a function.");
var InvalidObject = new Error("Missing valid object or an array of valid objects.");
var InvalidMethod = new Error("Missing valid method to apply aspect on.");
-function doBefore(beforeFunc,func){
- return function(){
- beforeFunc.apply(this,arguments);
- return func.apply(this,arguments);
- };
-}
-
-function doAfter(func, afterFunc){
- return function(){
- var res = func.apply(this,arguments);
- afterFunc.apply(this,arguments);
- return res;
- };
-}
-
function doAround(func, aroundFunc){
return function(){
aroundFunc.prototype._innerFunc = func
@@ -41,7 +43,6 @@ Aspects.prototype={
throw(InvalidAspect);
if (oType == 'function'){
- var tt = this
_addIntroduction(aspect, objs);
}
else if (oType == 'object'){
@@ -54,47 +55,6 @@ Aspects.prototype={
}
},
- addBefore : function(aspect, obj, funcs){
- var fType = typeof(funcs);
-
- if (typeof(aspect) != 'function')
- throw(InvalidAspect);
-
- if (fType != 'object')
- funcs = Array(funcs);
-
- for (var n = 0; n < funcs.length; n++){
- var fName = funcs[n];
- var old = obj.prototype[fName];
-
- if (!old)
- throw InvalidMethod;
-
- var res = doBefore(aspect,old)
- obj.prototype[fName] = res;
- }
- },
-
- addAfter : function(aspect, obj, funcs) {
- if (typeof(aspect) != 'function')
- throw InvalidAspect;
-
- if (typeof(funcs) != 'object')
- funcs = Array(funcs);
-
- for (var n = 0; n < funcs.length; n++)
- {
- var fName = funcs[n];
- var old = obj.prototype[fName];
-
- if (!old)
- throw InvalidMethod;
-
- var res = doAfter(old,aspect);
- obj.prototype[fName] = res;
- }
- },
-
addAround : function(aspect, obj, funcs){
if (typeof(aspect) != 'function')
throw InvalidAspect;
@@ -120,6 +80,4 @@ Aspects.prototype={
}
exports.addIntroduction = Aspects.prototype.addIntroduction
-exports.addBefore = Aspects.prototype.addBefore
-exports.addAfter = Aspects.prototype.addAfter
exports.addAround = Aspects.prototype.addAround
@@ -7,6 +7,7 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,8 +29,7 @@ var _ = require('underscore'),
jsonfill = require('../jsonfill.js'),
FormData = require('form-data'),
util = require('util'),
- charlie = require('charlie'),
- aop = require('../aop.js');
+ charlie = require('charlie');
var maxResponseLength;
@@ -36,7 +36,8 @@ exports.require = function() {
var splitpath = process.cwd().split('/');
splitpath[splitpath.length-1] = name;
args[0] = splitpath.join('/');
- return module.require.apply(null, args);
+ return module.require.a
+ pply(null, args);
} catch(e) {
args[0] = __dirname + '/' + name;
@@ -1,5 +1,6 @@
/*
-* Copyright 2013 eBay Software Foundation
+* Code taken from Danne Lundqvist with custom modification
+* http://www.dotvoid.com/2005/06/aspect-oriented-programming-and-javascript/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
"use strict";
-var Engine = require('../lib/engine');
-
+var Engine = require('../lib/engine'),
+ http = require('http');
module.exports = {
@@ -47,5 +47,49 @@ module.exports = {
test.done();
});
}, true);
+ },
+ 'auth-ok': function (test) {
+ var server = http.createServer(function (req, res) {
+ res.writeHead(200, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({'message': 'ok'}));
+ });
+ server.listen(3000, function () {
+ // Do the test here.
+ var engine = new Engine({
+ tables: __dirname + '/auth'
+ });
+ var events = []
+ engine.execute('select * from auth.plugin where ok = "ok"', function (emitter) {
+ engine.on('ql.io-event',function(event){
+ events.push(event)
+ })
+ engine.on('ql.io-begin-event',function(event){
+ events.push(event)
+ })
+ engine.on('ql.io-end-event',function(event){
+ events.push(event)
+ })
+ emitter.on('end', function (err, result) {
+ if(err) {
+ console.log(err.stack || util.inspect(err, false, 10));
+ test.fail('got error');
+ test.done();
+ }
+ else {
+ test.equals(events.length, 13)
+ test.equals(events[4].name,'http-request')
+ test.equals(events[5].name,'processingEvent')
+ test.equals(events[6].name,'http-request')
+ test.equals(events[7].name,'processingEvent')
+ test.equals(result.headers['content-type'], 'application/json', 'json expected');
+ test.equals(result.body.message, 'ok');
+ test.done();
+ }
+ server.close();
+ });
+ });
+ });
}
};
@@ -84,7 +84,7 @@ module.exports = {
}
else {
test.ok(!eventIdOne, "1 is unexpected event id");
- test.ok(!parentEventIdZero, "0 is unexpected parent event id");
+ test.ok(parentEventIdZero == 4, "4 is unexpected parent event id");
test.done();
server.close();
}

0 comments on commit d56e432

Please sign in to comment.