var Event = require('../../lib/event/Event.js').Event;
var RequestProcessor;
describe('RequestProcessor', function () {
    it('request', function () {
        RequestProcessor = require('../../lib/http/RequestProcessor.js').RequestProcessor;
        expect(RequestProcessor).toBeTruthy();
    });
    
    it('create instance', function () {
        expect(function () {
            var rp = new RequestProcessor();
        }).not.toThrow();
    });
    
    it('process request', function () {
        var Request = require('../../lib/http/Request.js').Request,
            Response = require('../../lib/http/Response.js').Response,
            req = new Request(), res = new Response(), logged;
            
        res._httpServerResponse = {'socket':
            {
                'on' : function () {
  
                },
                listeners : function () {
                    return {
                        length: 1
                    };
                },
                once : function () {}
            }
        };
        
        runs(function () {
            spyOn(console, 'info');
            console.info.andCallFake(function () {
                logged = true;
            });
            var rp = new RequestProcessor();
            rp.process(req, res);
            process.nextTick(function () {
                res.dispatchEvent(new Event(Response.Event.SEND, null));
            });
        });
        
        waitsFor(function () {
            return logged != undefined;
        });
        
        runs(function () {
            expect(req.getHeader('X-RID')).not.toEqual(null);
            expect(logged).toEqual(true);            
        })
        
        
    });
})