diff --git a/README b/README index ca23594..cd96646 100644 --- a/README +++ b/README @@ -80,7 +80,7 @@ client will prompt you to select a server. -------------------------------------------------------------------------------- NEW: Node.js tests for DIAL server 2.1 -------------------------------------------------------------------------------- -Node.js tests to test DIAL server implementation are now available under +Node.js tests to test DIAL server 2.1 implementation are now available under server/tests/js_tests. To run these tests againsts a DIAL server: 1. Ensure that the DIAL server is discoverable from the test environment @@ -92,21 +92,30 @@ The tests themselves are located inside the server/tests/js_tests/tests folder. The file tests.js is a batch runner and will run all the tests serially. It takes the following arguments: - host: - app: Name of the application to test against (eg: Netflix, YouTube) - timeToWaitForStateChange: Some of these tests wait for application state - changes before querying for application status. Default is 5000(ms) +server/tests/js_tests/tests$ node tests.js + +Usage: node tests.js[options] + +Options: + --host IP address of host on which DIAL server + under test is running [string] [required] + --application, --app Application to test [string] [required] + --timeToWaitForStateChange, --ttw Time(ms) to wait between state changes + before querying application status + [string] [default: 5000] + --help, -h Show help [boolean] + + +To run each test independantly and not through tests.js, just call the +appropriate test file name. Example: -server/tests/js_tests/tests> node tests.js host= -app="Netflix" timeToWaitForStateChange=2000 +server/tests/js_tests/tests$ node discoverServerUnderTest.js -To run each test independantly and not through test.js, just call the -appropriate test file name instead of test.js. +Usage: node discoverServerUnderTest.js[options] -Example: -server/tests/js_tests/tests> node discoverServerUnderTest.js -host= app="Netflix" timeToWaitForStateChange=2000 - -Any application specific setup/requirements should be taken care of before -running these tests. +Options: + --host IP address of host on which DIAL server under test is + running [string] [required] + --application, --app Application to test [string] [required] + --help, -h Show help [boolean] diff --git a/server/tests/js_tests/libs/dialClient.js b/server/tests/js_tests/libs/dialClient.js index 6ab8624..2c90377 100644 --- a/server/tests/js_tests/libs/dialClient.js +++ b/server/tests/js_tests/libs/dialClient.js @@ -65,8 +65,7 @@ function getApplicationStatus(host, app, clientDialVer) { if(statusCode !== 200) { return reject(new Error("Expected statusCode 200 while querying application status but got " + statusCode)); } - // TODO: Remove application/xml from accepted types - if(contentType.indexOf("text/xml") === -1 && contentType.indexOf("application/xml") === -1) { + if(contentType.indexOf("text/xml") === -1) { return reject(new Error("Expected MIME type 'text/xml' while querying application status but got " + contentType)); } // Extract fields from body @@ -121,8 +120,6 @@ function launchApplication(host, app, payload) { method: "POST", timeout: 6000, headers: { - // TODO: Remove host header - "Host" : appResourceUrl.split("http://")[1].split("/")[0], "Content-Type" : "text/plain;charset=\"utf-8\"" } }; @@ -162,9 +159,7 @@ function stopApplication(host, app) { var request = { url: appResourceUrl, method: "DELETE", - timeout: 6000, - // TODO: Remove host header - headers: {"Host" : appResourceUrl.split("http://")[1].split("/")[0]} + timeout: 6000 }; return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { @@ -193,9 +188,7 @@ function hideApplication(host, app) { var request = { url: appResourceUrl, method: "POST", - timeout: 6000, - // TODO: Remove host header - headers: {"Host" : appResourceUrl.split("http://")[1].split("/")[0]} + timeout: 6000 }; return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { @@ -218,9 +211,7 @@ function stopApplicationInstance(instanceUrl) { var request = { url: instanceUrl, method: "DELETE", - timeout: 6000, - // TODO: Remove host header - headers: {"Host" : instanceUrl.split("http://")[1].split("/")[0]} + timeout: 6000 }; return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { @@ -239,9 +230,7 @@ function hideApplicationInstance(instanceUrl) { var request = { url: instanceUrl, method: "POST", - timeout: 6000, - // TODO: Remove host header - headers: {"Host" : instanceUrl.split("http://")[1].split("/")[0]} + timeout: 6000 }; return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { diff --git a/server/tests/js_tests/libs/utils.js b/server/tests/js_tests/libs/utils.js index 14dce26..7d132ef 100644 --- a/server/tests/js_tests/libs/utils.js +++ b/server/tests/js_tests/libs/utils.js @@ -3,30 +3,18 @@ const colors = require("colors/safe"); const sprintf = require("sprintf-js").sprintf; -function getParam(key) { - var value; - var args = process.argv.slice(2); - args.forEach(function (param) { - if(param.indexOf(key + "=") === 0) { - value = param.split("=")[1]; - } - }); - return value; -} - function printTestInfo(test, msg) { return console.log(sprintf("%-20s : %-s\n%-20s : %-s", "Test", test, "Description", msg)); } -function printSuccess() { +function printTestSuccess() { return console.log(colors.green("TEST PASSED\n")); } -function printFailure(err) { +function printTestFailure(err) { return console.log(colors.red(sprintf("%-20s : %-s\n", "TEST FAILED", err))); } -module.exports.getParam = getParam; -module.exports.printTestInfo = printTestInfo; -module.exports.printSuccess = printSuccess; -module.exports.printFailure = printFailure; +module.exports.printTestInfo = printTestInfo; +module.exports.printTestSuccess = printTestSuccess; +module.exports.printTestFailure = printTestFailure; diff --git a/server/tests/js_tests/tests/discoverServerUnderTest.js b/server/tests/js_tests/tests/discoverServerUnderTest.js index 63f9694..4432b15 100644 --- a/server/tests/js_tests/tests/discoverServerUnderTest.js +++ b/server/tests/js_tests/tests/discoverServerUnderTest.js @@ -39,10 +39,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/hideApplicationInHiddenState.js b/server/tests/js_tests/tests/hideApplicationInHiddenState.js index d87715a..d68b446 100644 --- a/server/tests/js_tests/tests/hideApplicationInHiddenState.js +++ b/server/tests/js_tests/tests/hideApplicationInHiddenState.js @@ -88,10 +88,10 @@ function test() { }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/hideApplicationInRunningState.js b/server/tests/js_tests/tests/hideApplicationInRunningState.js index 4b01e58..eaff82d 100644 --- a/server/tests/js_tests/tests/hideApplicationInRunningState.js +++ b/server/tests/js_tests/tests/hideApplicationInRunningState.js @@ -81,10 +81,10 @@ function test() { }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js index af3be99..11e2f86 100644 --- a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js +++ b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js @@ -71,10 +71,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js index 42bb2fc..52237fb 100644 --- a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js @@ -81,10 +81,10 @@ function test() { }) .delay(timeToWaitForStateChange) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js index 6d05455..0d18d73 100644 --- a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js @@ -81,10 +81,10 @@ function test() { }) .delay(timeToWaitForStateChange) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js index 35ee524..35eae0c 100644 --- a/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js @@ -79,10 +79,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js index 8c7f587..1f1d187 100644 --- a/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js @@ -80,10 +80,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js index def0569..cd6e6bd 100644 --- a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js @@ -81,10 +81,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js index 343c54c..ca17e6e 100644 --- a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js @@ -81,10 +81,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationNotRecognized.js b/server/tests/js_tests/tests/launchApplicationNotRecognized.js index 82fb0e5..c985a46 100644 --- a/server/tests/js_tests/tests/launchApplicationNotRecognized.js +++ b/server/tests/js_tests/tests/launchApplicationNotRecognized.js @@ -40,10 +40,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js index ee7f90e..d9e22e3 100644 --- a/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js +++ b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js @@ -68,10 +68,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInHiddenState.js b/server/tests/js_tests/tests/stopApplicationInHiddenState.js index 7500cc3..a8c23fd 100644 --- a/server/tests/js_tests/tests/stopApplicationInHiddenState.js +++ b/server/tests/js_tests/tests/stopApplicationInHiddenState.js @@ -88,10 +88,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInRunningState.js b/server/tests/js_tests/tests/stopApplicationInRunningState.js index f93dd52..90e1f29 100644 --- a/server/tests/js_tests/tests/stopApplicationInRunningState.js +++ b/server/tests/js_tests/tests/stopApplicationInRunningState.js @@ -80,10 +80,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInStoppedState.js b/server/tests/js_tests/tests/stopApplicationInStoppedState.js index d40ebbb..fa048c8 100644 --- a/server/tests/js_tests/tests/stopApplicationInStoppedState.js +++ b/server/tests/js_tests/tests/stopApplicationInStoppedState.js @@ -107,10 +107,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); } diff --git a/server/tests/js_tests/tests/stopInvalidApplicationInstance.js b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js index 12d1101..db69719 100644 --- a/server/tests/js_tests/tests/stopInvalidApplicationInstance.js +++ b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js @@ -67,10 +67,10 @@ function test() { } }) .then(function () { - utils.printSuccess() + utils.printTestSuccess() }) .fail(function handleError(err) { - utils.printFailure(err); + utils.printTestFailure(err); }); }