"use strict";
var fs=require('fs');
var data = 0;
var validJSON = null;

function validateTestsJSON(callback)
{
	fs.open('./tests.json', 'r', function(err, fd) {
	    fs.fstat(fd, function(err, stats) {
	        var bufferSize = stats.size,
	            chunkSize = 512,
	            buffer = new Buffer(bufferSize),
	            bytesRead = 0;

	        while (bytesRead < bufferSize) {
	            if ((bytesRead + chunkSize) > bufferSize) {
	                chunkSize = (bufferSize - bytesRead);
	            }
	            fs.read(fd, buffer, bytesRead, chunkSize, bytesRead);
	            bytesRead += chunkSize;
	        }
	        data = buffer.toString('utf8', 0, bufferSize);
	        fs.close(fd);

	        try {
				validJSON = JSON.parse(data);
				callback(validJSON);
	        }
	        catch(err) {
	        	console.log("File is not written in a valid JSON Format");
	        	callback(false);
	        }
	        
	    });
	});
}

function validateTestFormat(validJSON)
{
	if(!validJSON)
	{
		return false;
	}
	else
	{
		console.log(validJSON);
		if(typeof validJSON.name == "string" && typeof validJSON.url == "string" && typeof validJSON.testgroups == "object" && typeof validJSON.port == "number")
		{
			for (var i = validJSON.testgroups.length - 1; i >= 0; i--) 
			{
				if(typeof validJSON.testgroups[i].groupname == "string" && typeof validJSON.testgroups[i].tests == "object")
				{
					for (var j = validJSON.testgroups[i].tests.length - 1; j >= 0; j--)
					{
						if( typeof validJSON.testgroups[i].tests[j].name == "string" && 
							typeof validJSON.testgroups[i].tests[j].uri == "string" && 
							typeof validJSON.testgroups[i].tests[j].input == "object" && 
							typeof validJSON.testgroups[i].tests[j].output == "object" && 
							typeof validJSON.testgroups[i].tests[j].input.data == "object" && 
							typeof validJSON.testgroups[i].tests[j].input.data.username == "string" && 
							typeof validJSON.testgroups[i].tests[j].input.data.password == "string" &&
							typeof validJSON.testgroups[i].tests[j].output.responseStatus == "string") 
						{
							console.log("Correct JSON Format");
						}
						else
						{
							console.log("Invalid JSON Format");
						}
					}
				}
				else
				{
					console.log("Invalid JSON Format");
				}
			}	
		}
		else
		{
			console.log("Invalid JSON Format");
		}
	}
	
}

validateTestsJSON(validateTestFormat);

@@ -7,16 +7,61 @@
 trict%22;%0A
+var testRunner = require(%22./testrunner.js%22);%0A
 var fs=r
@@ -92,21 +92,21 @@
  0;%0Avar 
-valid
+tests
 JSON = n
@@ -767,16 +767,20 @@
 y %7B%0A%09%09%09%09
+var 
 validJSO
@@ -1085,34 +1085,8 @@
 %0A%09%7B%0A
-%09%09console.log(validJSON);%0A
 %09%09if
@@ -1784,332 +1784,8 @@
 ect%22
- && %0A%09%09%09%09%09%09%09typeof validJSON.testgroups%5Bi%5D.tests%5Bj%5D.input.data == %22object%22 && %0A%09%09%09%09%09%09%09typeof validJSON.testgroups%5Bi%5D.tests%5Bj%5D.input.data.username == %22string%22 && %0A%09%09%09%09%09%09%09typeof validJSON.testgroups%5Bi%5D.tests%5Bj%5D.input.data.password == %22string%22 &&%0A%09%09%09%09%09%09%09typeof validJSON.testgroups%5Bi%5D.tests%5Bj%5D.output.responseStatus == %22string%22
 ) %0A%09
@@ -1993,16 +1993,66 @@
 %7D%0A%09%09%09%7D%09%0A
+%09%09%09testsJSON = validJSON;%0A%09%09%09runTests(testsJSON);%0A
 %09%09%7D%0A%09%09el
@@ -2109,16 +2109,426 @@
 %09%7D%0A%09%0A%7D%0A%0A
+function runTests(testsJSON)%0A%7B%0A%09for (var i = testsJSON.testgroups.length - 1; i %3E= 0; i--) %0A%09%7B%0A%09%09for (var j = testsJSON.testgroups%5Bi%5D.tests.length - 1; j %3E= 0; j--)%0A%09%09%7B%0A%09%09%09var test = new testRunner();%0A%0A%09%09%09test.run(testsJSON.testgroups%5Bi%5D.tests%5Bj%5D.name, testsJSON.url,testsJSON.port,testsJSON.testgroups%5Bi%5D.tests%5Bj%5D.uri,testsJSON.testgroups%5Bi%5D.tests%5Bj%5D.input,testsJSON.testgroups%5Bi%5D.tests%5Bj%5D.output);%0A%09%09%7D%0A%09%7D%0A%7D%0A%0A
 validate

test runner implemented