Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component tests #178

Merged
merged 18 commits into from
Sep 19, 2013
13 changes: 6 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ module.exports = function (grunt) {
src: ['lib/**/*.js']
},
test: {
src: ['test/e2e/*Test.js']
},
testAll : {
src: ['test/e2e/*Check.js']
src: ['test/e2e/*Test.js', 'test/component/*Test.js']
}
},
watch: {
Expand All @@ -47,7 +44,8 @@ module.exports = function (grunt) {
},
src: [
'mocha-globals.js',
'test/e2e/*Test.js'
'test/e2e/*Test.js',
'test/component/*Test.js'
]
},
check : {
Expand All @@ -58,9 +56,10 @@ module.exports = function (grunt) {
},
src: [
'mocha-globals.js',
'test/e2e/*Check.js'
'test/e2e/*Check.js',
'test/component/*Check.js'
]
},
}

},

Expand Down
5 changes: 3 additions & 2 deletions lib/configBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ gevLsnr.take = {id: 'id', topic: 'topic', body: 'task.body',
*/
exports.consumer.evModules = [
{module: './evCallback'},
{module: './evPersistence'}
{module: './evPersistence'},
{module: './evMonitor'}
// ,{module: './gevLsnr', config: gevLsnr}
];


exports.listener.evModules = [
{module: './evPersistence'}
];
];
17 changes: 17 additions & 0 deletions lib/evMonitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var MG = require("./myGlobals").C;
var redis = require('redis');
var config = require('./configBase.js');

var rc = redis.createClient(config.redisPort, config.redisHost);

function init(emitter) {
"use strict";
return function(callback) {
emitter.on(MG.EVENT_NEWSTATE, function onNewEvent(data) {
rc.publish('STATE:' + data.state, JSON.stringify(data));
});
callback(null, 'evMonitor OK');
};
}

exports.init = init;
14 changes: 14 additions & 0 deletions lib/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,22 @@ function startListening(done) {
next();
}

function cleanBlankHeaders(req, res, next) {

for (var header in req.headers) {
if (req.headers.hasOwnProperty(header)) {
if (req.headers[header] === '') {
delete req.headers[header];
}
}
}

next();
}

app = express();
app.use(dbCluster.checkAvailable);
app.use(cleanBlankHeaders);
app.use(setLogProperties);
app.get('/response/:id_response', responsePath);
app.all('/*', relayReq);
Expand Down
100 changes: 0 additions & 100 deletions test/component/bugs.js

This file was deleted.

1 change: 1 addition & 0 deletions test/component/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.rushServerHttps = {hostname: 'localhost', port: 5002};
exports.callBackPort = 8015;
exports.simpleServerHostname = '127.0.0.1';
exports.simpleServerPort = 8014;

exports.externalEndpoint = 'www.google.es';
exports.externalEndpointPort = 8080;

Expand Down
125 changes: 125 additions & 0 deletions test/component/onewayTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
var should = require('should');
var chai = require('chai');
var superagent = require('superagent');
var config = require('./config.js');
var redis = require('redis');
var _ = require('underscore');

var expect = chai.expect;

var HOST = config.rushServer.hostname;
var PORT = config.rushServer.port;

var listener = require('../../lib/listener.js');
var consumer = require('../../lib/consumer.js');

var REDIS_HOST = config.redisServer.host;
var REDIS_PORT = config.redisServer.port;

var URL_RUSH = 'http://' + HOST + ':' + PORT;
var ENDPOINT = config.externalEndpoint;


// Verbose MODE
var vm = false;
// Time to wait to check the status of the task
var TIMEOUT = 1000;
var describeTimeout = 60000;
var QUEUE = "wrL:hpri"; //Task

var ALL_HEADERS = [
"x-relayer-persistence",
"x-relayer-httpcallback",
"x-relayer-httpcallback-error",
"x-relayer-retry",
"x-relayer-topic",
"x-relayer-proxy",
"x-relayer-encoding"
];

describe('Component Test: Task queue', function () {
this.timeout(describeTimeout);

before(function (done) {
listener.start(done);
});

after(function (done) {
listener.stop(done);
});

var agent = superagent.agent();
var rc = redis.createClient(REDIS_PORT, REDIS_HOST);
rc.flushall();

var dataSet = [
{method: 'GET', headers: {}, name :
"Case 1 Task should contain OneWay policy #FOW" },
{method: 'GET', headers: {"x-relayer-persistence" : "STATUS"}, name :
"Case 2 Task should contain STATUS persistence #FPT"},
{method: 'GET', headers: {"x-relayer-persistence" : "HEADER"}, name :
"Case 3 Task should contain HEADER persistence #FPT"},
{method: 'GET', headers: {"x-relayer-persistence" : "BODY"}, name :
"Case 4 Task should contain BODY persistence #FPT"},
{method: 'POST', headers: {"x-relayer-httpcallback" : "http://noname.com"}, name :
"Case 5 Task should contain x-relayer-httpcallback atribute #FCB"},
{method: 'POST', headers: {"x-relayer-httpcallback" : "http://noname.com", "x-relayer-httpcallback-error" : "http://noname.com"}, name :
"Case 6 Task should contain x-relayer-httpcallback and x-relayer-httpcallback-error #FCB"},
{method: 'POST', headers: {"x-relayer-retry" : "10, 20, 30"}, name :
"Case 7 Task should have property x-relayer-retry #FRT"},
{method: 'PUT', headers: {}, name :
"Case 8 Task should be stored #FOW"},
{method: 'PUT', headers: {'x-relayer-topic' : 'TEST'}, name :
"Case 9 Task should have property x-relayer-topic #FTP"},
{method: 'PUT', headers: {'x-relayer-proxy' : 'proxy.com'}, name :
"Case 10 Task should have property x-relayer-proxy #FPX"},
{method: 'PUT', headers: {'x-relayer-encoding' : 'base64'}, name :
"Case 11 Task should have property x-relayer-encoding #FEN"}
];

for(var i=0; i < dataSet.length; i++){
_newScenario(dataSet[i])(); //Launch every test in data set
}

function _newScenario(data){
return function(){
it(data.name + " /" + data.method, function(done){
agent
[data.method.toLowerCase()](URL_RUSH)
.set('x-relayer-host', ENDPOINT) //Always the same endpoint
.set(data.headers)
.end(function(err, res) {
expect(err).to.not.exist;
expect(res.statusCode).to.equal(201); //Status code 201
expect(res.body).to.exist;
expect(res.body.id).to.exist;

var transId = res.body.id;
rc.lpop(QUEUE, function(err, res){
expect(err).to.not.exist;

var task = JSON.parse(res);
expect(task.id).to.equal(transId);
expect(task).to.have.property('headers');
expect(task).to.have.property('method');
expect(task.method).to.equal(data.method);
expect(task.headers).to.have.property('x-relayer-host');
expect(task.headers['x-relayer-host']).to.equal(ENDPOINT);

for(var header in data.headers){ //every header in the request must be inside the current task
var head = header.toLowerCase();
expect(task.headers).to.have.property(head);
expect(task.headers[head]).to.equal(data.headers[head]);
}

var shouldNotExist = _.difference(ALL_HEADERS, Object.keys(data.headers)); //headers that aren't in the request
for(var i=0; i < shouldNotExist.length; i++){ //there should not be headers in the task that are not in the request
expect(task.headers).to.not.have.property(shouldNotExist[i]);
}
done();
});
});
});
};
}
});
Loading