diff --git a/server/tests/js_tests/libs/dialClient.js b/server/tests/js_tests/libs/dialClient.js index ba2509b..6ab8624 100644 --- a/server/tests/js_tests/libs/dialClient.js +++ b/server/tests/js_tests/libs/dialClient.js @@ -42,7 +42,7 @@ function discover() { } function getApplicationStatus(host, app, clientDialVer) { - clientDialVer = clientDialVer || "2.1"; // To test backward compatibility + clientDialVer = clientDialVer || "2.1"; // To test backward compatibility, 2.1 by default return new Q() .then(constructAppResourceUrl.bind(null, host, app)) @@ -63,15 +63,15 @@ function getApplicationStatus(host, app, clientDialVer) { var statusCode = response.statusCode; var contentType = response.headers["content-type"]; if(statusCode !== 200) { - return reject(new Error("Expected statusCode 200 while querying app status but got " + statusCode)); + 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) { - return reject(new Error("Expected MIME type 'text/xml' while querying app status but got " + contentType)); + return reject(new Error("Expected MIME type 'text/xml' while querying application status but got " + contentType)); } // Extract fields from body try { - if(body.indexOf("xmlns") === -1 || body.indexOf("name") === -1 || body.indexOf("state") === -1) { + if(body.indexOf("xmlns") === -1 || body.indexOf("") === -1 || body.indexOf("") === -1) { return reject(new Error("One or more required fields were not present in the application status response")); } var parsedResponse = { @@ -79,6 +79,9 @@ function getApplicationStatus(host, app, clientDialVer) { "name" : body.split("")[1].split("")[0].replace(/\s/g, ""), "state" : body.split("")[1].split("")[0].replace(/\s/g, "") }; + if(parsedResponse.xmlns !== "urn:dial-multiscreen-org:schemas:dial") { + return reject(new Error("xmlns is not 'urn:dial-multiscreen-org:schemas:dial' in the app status response " + parsedResponse.xmlns)); + } if(body.indexOf("dialVer") !== -1) { parsedResponse.dialVer = body.split("dialVer=")[1].split(" ")[0].split(">")[0].replace(/\s/g, "").replace(/\"/g, ""); @@ -89,24 +92,20 @@ function getApplicationStatus(host, app, clientDialVer) { if(body.indexOf("")[0].replace(/\"/g, ""); if(parsedResponse.rel !== "run") { - return reject(new Error("link rel is not 'run' in the application status response")); + return reject(new Error("@rel attribute is not 'run' in the application status response")); } parsedResponse.href = body.split("href=")[1].split(" ")[0].split("/>")[0].replace(/\s/g, "").replace(/\"/g, ""); } if(body.indexOf("") !== -1) { parsedResponse.additionalData = body.split("")[1].split("")[0].replace(/\s/g, ""); } - if(parsedResponse.xmlns !== "urn:dial-multiscreen-org:schemas:dial") { - return reject(new Error("xmlns is not 'urn:dial-multiscreen-org:schemas:dial' in the app status response " + parsedResponse.xmlns)); - } - return resolve(parsedResponse); } catch (err) { - return reject(new Error("There was a problem extracting fields from app status. Status returned : " + body)); + return reject(new Error("There was a problem extracting one or more fields from application status. Status returned : \n" + body)); } } - return Q.reject(new Error("Error getting app status " + error)); + return reject(new Error("Error retrieving application status " + error)); }); }); }); @@ -115,6 +114,7 @@ function getApplicationStatus(host, app, clientDialVer) { function launchApplication(host, app, payload) { return new Q() .then(constructAppResourceUrl.bind(null, host, app)) + // TODO: Send friendlyName query parameter for DIAL 2.1 and greater versions of server .then(function (appResourceUrl) { var request = { url: appResourceUrl, @@ -123,7 +123,6 @@ function launchApplication(host, app, payload) { headers: { // TODO: Remove host header "Host" : appResourceUrl.split("http://")[1].split("/")[0], - // TODO: Check charset "Content-Type" : "text/plain;charset=\"utf-8\"" } }; @@ -138,7 +137,7 @@ function launchApplication(host, app, payload) { return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { if(!error) { - return resolve(response.statusCode); + return resolve(response); } return reject(new Error("Error launching application " + error)); }); @@ -155,7 +154,8 @@ function stopApplication(host, app) { if(response.href) { return appResourceUrl + "/" + response.href; // Construct Application Instance Url } - return Q.reject(new Error("Could not get instance href from application status to construct Application Instance Url")); + return Q.reject(new Error("Could not get attribute @href from application status to construct Application Instance Url. " + + "This means the DIAL server does not support STOP requests for this application.")); }); }) .then(function (appResourceUrl) { @@ -169,7 +169,7 @@ function stopApplication(host, app) { return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { if(!error) { - return resolve(response.statusCode); + return resolve(response); } return reject(new Error("Error stopping application " + error)); }); @@ -200,7 +200,11 @@ function hideApplication(host, app) { return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { if(!error) { - return resolve(response.statusCode); + if(response.statusCode === 501) { + return reject("HIDE request returned 501 NOT IMPLEMENTED. " + + "This means the DIAL server does not support HIDE for this application."); + } + return resolve(response); } return reject(new Error("Error hiding application " + error)); }); @@ -221,7 +225,7 @@ function stopApplicationInstance(instanceUrl) { return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { if(!error) { - return resolve(response.statusCode); + return resolve(response); } return reject(new Error("Error stopping application " + error)); }); @@ -242,7 +246,7 @@ function hideApplicationInstance(instanceUrl) { return new Q.Promise(function (resolve, reject) { return httpRequest(request, function handleResponse(error, response) { if(!error) { - return resolve(response.statusCode); + return resolve(response); } return reject(new Error("Error hiding application " + error)); }); diff --git a/server/tests/js_tests/tests/hideApplicationInHiddenState.js b/server/tests/js_tests/tests/hideApplicationInHiddenState.js new file mode 100644 index 0000000..8249c96 --- /dev/null +++ b/server/tests/js_tests/tests/hideApplicationInHiddenState.js @@ -0,0 +1,81 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Try to hide " + app + " when it is already in hidden state and expect response code 200 from the DIAL server"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function hideApp(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + if(result.state === "stopped") { + // Launch and hide app + return dial.launchApplication(host, app) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " app status to be running but the state was " + result.state)); + } + }) + .then(dial.hideApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange); + } + return dial.hideApplication(host, app) + .delay(timeToWaitForStateChange); + } + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state)); + } + }) + + .then(dial.hideApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Tried to hide " + app + ". Expected statusCode: 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state)); + } + }) + + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/hideApplicationInRunningState.js b/server/tests/js_tests/tests/hideApplicationInRunningState.js new file mode 100644 index 0000000..41f6d64 --- /dev/null +++ b/server/tests/js_tests/tests/hideApplicationInRunningState.js @@ -0,0 +1,74 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Hide " + app + " application when it is running and expect response code 200"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + return result.state; + }) + + .then(function startAppIfNotRunning(state) { + if(state !== "running") { + return dial.launchApplication(host, app) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Could not launch " + app + " application. Expected status code 201 but got " + response.statusCode)); + } + }); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state)); + } + }) + + .then(dial.hideApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Error hiding " + app + " application. Expected status code 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " state to be hidden but state was " + result.state)); + } + }) + + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js index 4f777f5..09204cf 100644 --- a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js +++ b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js @@ -6,42 +6,47 @@ var dial = require("../libs/dialClient.js"), function test() { var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; return new Q() .then(function () { - console.log("TEST " + __filename + ": Try to hide an invalid instance of Netflix application and expect status code 404"); + console.log("TEST " + __filename + ": Try to hide an invalid instance of " + app + " application and expect status code 404"); }) - .then(dial.launchApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 200 && status !== 201) { - return Q.reject(new Error("Error launching Netflix application. Expected status code 200/201 but got " + status)); + .then(dial.launchApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 but got " + response.statusCode)); } }) + .delay(timeToWaitForStateChange) .then(function () { - return dial.getApplicationStatus(host, "Netflix"); + return dial.getApplicationStatus(host, app); }) .then(function getCurrentAppState(result) { if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); + return Q.reject(new Error("Could not retrieve current " + app + " application state")); } - if(result.dialVer && result.dialVer !== "2.1") { - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state)); } - return result.state; }) .then(function () { return dial.getAppsUrl(host); }) .then(function (appsUrl) { - var invalidInstanceUrl = appsUrl + "/application/xyz"; + var invalidInstanceUrl = appsUrl + "/" + app + "/xyz"; return invalidInstanceUrl; }) .then(function (url) { return dial.hideApplicationInstance(url); }) - .then(function (status) { - if(status !== 404) { - return Q.reject(new Error("Tried to hide invalid application instance. Expected statusCode: 404 but got " + status)); + .then(function (response) { + if(response.statusCode === 501) { + return Q.reject(new Error("The DIAL server returned 501 NOT IMPLEMENTED. This means it does not support HIDE operation")); + } + if(response.statusCode !== 404) { + return Q.reject(new Error("Tried to hide invalid application instance. Expected statusCode: 404 but got " + response.statusCode)); } }) .then(function () { diff --git a/server/tests/js_tests/tests/hideNetflixWhenAlreadyHidden.js b/server/tests/js_tests/tests/hideNetflixWhenAlreadyHidden.js deleted file mode 100644 index f144380..0000000 --- a/server/tests/js_tests/tests/hideNetflixWhenAlreadyHidden.js +++ /dev/null @@ -1,67 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Try to hide netflix when it is already in hidden state and expect response code 200 from the DIAL server"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function hideApp(result) { - if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); - } - if(result.state !== "hidden") { - if(!result.dialVer || result.dialVer !== "2.1") { // Hidden state not supported - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); - } - - if(result.state === "stopped") { - // Launch and hide app - return dial.launchApplication(host, "Netflix") - .delay(5000) - .then(dial.hideApplication.bind(null, host, "Netflix")) - .delay(5000); - } - else if(result.state === "starting" || result.state === "running") { - // Hide app - return dial.hideApplication(host, "Netflix") - .delay(5000); - } - } - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function checkAppStatus(result) { - if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); - } - if(result.state !== "hidden") { - return Q.reject(new Error("Expected Netflix app status to be hidden but the state was " + result.state)); - } - }) - - .then(dial.hideApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Tried to hide Netflix. Expected statusCode: 200 but got " + status)); - } - }) - .delay(5000) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/hideNetflixWhenRunning.js b/server/tests/js_tests/tests/hideNetflixWhenRunning.js deleted file mode 100644 index a249bcc..0000000 --- a/server/tests/js_tests/tests/hideNetflixWhenRunning.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Hide netflix application when it is running and expect response code 200"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); - } - if(result.dialVer && result.dialVer !== "2.1") { - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); - } - return result.state; - }) - - .then(function startAppIfNotRunning(state) { - if(state !== "running") { - return dial.launchApplication(host, "Netflix") - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Could not launch Netflix application. Expected status code 201 but got " + status)); - } - }); - } - }) - .delay(5000) // Allow time for app to start - - .then(dial.hideApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Error stopping Netflix application. Expected status code 200 but got " + status)); - } - }) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchAppNotRecognized.js b/server/tests/js_tests/tests/launchAppNotRecognized.js deleted file mode 100644 index 14933e7..0000000 --- a/server/tests/js_tests/tests/launchAppNotRecognized.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Launch an invalid application using DIAL server and check for response code 404"); - }) - .then(dial.launchApplication.bind(null, host, "InvalidApplication")) - .then(function (status) { - if(status !== 404) { - return Q.reject(new Error("Tried to launch invalid application using DIAL server. Expected statusCode: 404 but got " + status)); - } - }) - .then(dial.launchApplication.bind(null, host, "InvalidApplication", "key1=val1&key2=val2")) - .then(function (status) { - if(status !== 404) { - return Q.reject(new Error("Tried to launch invalid application with a payload using DIAL server. Expected statusCode: 404 but got " + status)); - } - }) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js new file mode 100644 index 0000000..51206d9 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js @@ -0,0 +1,74 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + " Launch " + app + " application using DIAL server when app is in hidden state and check for response code 201 "); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function hideApp(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "hidden") { + if(result.state === "stopped") { + // Launch and hide app + return dial.launchApplication(host, app) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state)); + } + }) + .then(dial.hideApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange); + } + else { + // Hide app + return dial.hideApplication(host, app) + .delay(timeToWaitForStateChange); + } + } + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state)); + } + }) + + .then(dial.launchApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application when it was in hidden state. Expected statusCode: 201 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js new file mode 100644 index 0000000..9fb1861 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js @@ -0,0 +1,74 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + " Launch " + app + " application with payload using DIAL server when app is in hidden state and check for response code 201 "); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function hideApp(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "hidden") { + if(result.state === "stopped") { + // Launch and hide app + return dial.launchApplication(host, app) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state)); + } + }) + .then(dial.hideApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange); + } + else { + // Hide app + return dial.hideApplication(host, app) + .delay(timeToWaitForStateChange); + } + } + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state)); + } + }) + + .then(dial.launchApplication.bind(null, host, app, "key1=val1")) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application when it was in hidden state. Expected statusCode: 201 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js new file mode 100644 index 0000000..aced674 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js @@ -0,0 +1,72 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Launch " + app + " without payload using DIAL server when application is already running and check for response code 201"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + return result.state; + }) + + .then(function startAppIfNotRunning(state) { + if(state !== "running") { + return dial.launchApplication(host, app) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode)); + } + }); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + + .then(dial.launchApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application when it was already running. Expected status code 201 from DIAL server but got " + response.statusCode)); + } + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js new file mode 100644 index 0000000..37dbb52 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js @@ -0,0 +1,73 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Launch " + app + " with payload using DIAL server when application is already running and check for response code 201"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + return result.state; + }) + + .then(function startAppIfNotRunning(state) { + if(state !== "running") { + return dial.launchApplication(host, app) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode)); + } + }); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + + .then(dial.launchApplication.bind(null, host, app, "key1=val1")) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application when it was already running. Expected status code 201 from DIAL server but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) // Allow time for restart if application supports sending new params + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js new file mode 100644 index 0000000..1e83ca0 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js @@ -0,0 +1,74 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Launch " + app + " application using DIAL server when the application is in STOPPED state and expect response code 201"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function stopAppIfNecessary(result) { + if(!result || !result.state) { + return Q.reject("Error retrieving " + app + " application state"); + } + if(result.state !== "stopped") { + if(!result.href) { + return Q.reject(new Error("Unable to to retrive href attribute from application status. This means the DIAL server does not support STOP operation. " + + "Test cannot proceed. Stop the " + app + " app manually before re-running this test")); + } + return dial.stopApplication(host, app) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Could not stop " + app + " application when it was in " + result.state + " state. Expected status code 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppState(result) { + if(!result || !result.state) { + return Q.reject("Error retrieving " + app + " application state"); + } + if(result.state !== "stopped") { + return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state)); + } + }); + } + return result.state; + }) + + .then(dial.launchApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js new file mode 100644 index 0000000..8457bd5 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js @@ -0,0 +1,74 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Launch " + app + " application with payload using DIAL server when the application is in STOPPED state and expect response code 201"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function stopAppIfNecessary(result) { + if(!result || !result.state) { + return Q.reject("Error retrieving " + app + " application state"); + } + if(result.state !== "stopped") { + if(!result.href) { + return Q.reject(new Error("Unable to to retrieve href attribute from application status. This means the DIAL server does not support STOP operation. " + + "Test cannot proceed. Stop the " + app + " app manually before re-running this test")); + } + return dial.stopApplication(host, app) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Could not stop " + app + " application when it was in " + result.state + " state. Expected status code 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppState(result) { + if(!result || !result.state) { + return Q.reject("Error retrieving " + app + " application state"); + } + if(result.state !== "stopped") { + return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state)); + } + }); + } + return result.state; + }) + + .then(dial.launchApplication.bind(null, host, app, "key1=val1")) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchApplicationNotRecognized.js b/server/tests/js_tests/tests/launchApplicationNotRecognized.js new file mode 100644 index 0000000..5eec857 --- /dev/null +++ b/server/tests/js_tests/tests/launchApplicationNotRecognized.js @@ -0,0 +1,33 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Launch an application that is not recognized by DIAL server and check for response code 404"); + }) + .then(dial.launchApplication.bind(null, host, "ApplicationNotRecognized")) + .then(function (response) { + if(response.statusCode !== 404) { + return Q.reject(new Error("Tried to launch application that is not recognized by the DIAL server. Expected statusCode: 404 but got " + response.statusCode)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/launchNetflixWithExcessPayload.js b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js similarity index 92% rename from server/tests/js_tests/tests/launchNetflixWithExcessPayload.js rename to server/tests/js_tests/tests/launchApplicationWithExcessPayload.js index 97fd799..0e58643 100644 --- a/server/tests/js_tests/tests/launchNetflixWithExcessPayload.js +++ b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js @@ -6,6 +6,7 @@ var dial = require("../libs/dialClient.js"), function test() { var host = utils.getParam("host"); + var app = utils.getParam("app"); var payload = "key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&" + "key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&key=value&" @@ -43,12 +44,12 @@ function test() { return new Q() .then(function () { - console.log("TEST " + __filename + ": Try to launch Netflix app with excess payload and ensure DIAL server returns response code 413"); + console.log("TEST " + __filename + ": Try to launch " + app + " application with excess payload and ensure DIAL server returns response code 413"); }) - .then(dial.launchApplication.bind(null, host, "Netflix", payload)) - .then(function (status) { - if(status !== 413) { - return Q.reject(new Error("Tried to launch Netflix with excess payload. Expected statusCode: 413 but got " + status)); + .then(dial.launchApplication.bind(null, host, app, payload)) + .then(function (response) { + if(response.statusCode !== 413) { + return Q.reject(new Error("Tried to launch " + app + " with excess payload. Expected statusCode: 413 but got " + response.statusCode)); } }) .then(function () { diff --git a/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithNoPayload.js b/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithNoPayload.js deleted file mode 100644 index 83faea3..0000000 --- a/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithNoPayload.js +++ /dev/null @@ -1,52 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Launch Netflix without payload using DIAL server when application is already running and check for response code 200/201"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - return result.state; - }) - - .then(function startAppIfNotRunning(state) { - if(state !== "starting" || state !== "running") { - return dial.launchApplication(host, "Netflix") - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application. Expected status code 201 from DIAL server but got " + status)); - } - }); - } - }) - .delay(5000) - - .then(dial.launchApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 201 && status !== 200) { - return Q.reject(new Error("Error launching Netflix application when it was already running. Expected status code 200/201 from DIAL server but got " + status)); - } - }) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithPayload.js b/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithPayload.js deleted file mode 100644 index 1571f1a..0000000 --- a/server/tests/js_tests/tests/launchNetflixAlreadyRunningWithPayload.js +++ /dev/null @@ -1,52 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Launch Netflix with payload using DIAL server when application is already running and check for response code 200/201"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - return result.state; - }) - - .then(function startAppIfNotRunning(state) { - if(state !== "starting" || state !== "running") { - return dial.launchApplication(host, "Netflix") - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application. Expected status code 201 from DIAL server but got " + status)); - } - }); - } - }) - .delay(5000) - - .then(dial.launchApplication.bind(null, host, "Netflix", "key1=val1&key2=val2")) - .then(function (status) { - if(status !== 201 && status !== 200) { - return Q.reject(new Error("Error launching Netflix application when it was already running. Expected status code 200/201 from DIAL server but got " + status)); - } - }) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchNetflixNotRunningWithNoPayload.js b/server/tests/js_tests/tests/launchNetflixNotRunningWithNoPayload.js deleted file mode 100644 index 9283d2a..0000000 --- a/server/tests/js_tests/tests/launchNetflixNotRunningWithNoPayload.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Launch Netflix application using DIAL server when the application is in STOPPED state"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject("Could not retrieve current Netflix application state"); - } - if(result.state !== "stopped") { - if(result.allowStop && result.allowStop === "false") { - return Q.reject(new Error("The DIAL server does not support STOP operation. Test cannot proceed. Make sure the Netflix app is stopped before re-running the test")); - } - } - return result.state; - }) - .then(function stopAppIfCurrentlyRunning(state) { - if(state !== "stopped") { - return dial.stopApplication(host, "Netflix") - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Could not stop Netflix application when it was running. Expected status code 200 but got " + status)); - } - }); - } - }) - .delay(5000) - - .then(dial.launchApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application. Expected statusCode: 201 but got " + status)); - } - }) - .delay(5000) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchNetflixNotRunningWithPayload.js b/server/tests/js_tests/tests/launchNetflixNotRunningWithPayload.js deleted file mode 100644 index cf22d9e..0000000 --- a/server/tests/js_tests/tests/launchNetflixNotRunningWithPayload.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Launch Netflix application with payload using DIAL server when the application is in STOPPED state"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject("Could not retrieve current Netflix application state"); - } - if(result.state !== "stopped") { - if(result.allowStop && result.allowStop === "false") { - return Q.reject(new Error("The DIAL server does not support STOP operation. Test cannot proceed. Make sure the Netflix app is stopped before re-running the test")); - } - } - return result.state; - }) - .then(function stopAppIfCurrentlyRunning(state) { - if(state !== "stopped") { - return dial.stopApplication(host, "Netflix") - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Could not stop Netflix application when it was running. Expected status code 200 but got " + status)); - } - }); - } - }) - .delay(5000) - - .then(dial.launchApplication.bind(null, host, "Netflix", "key1=val1&key2=val2")) - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application. Expected statusCode: 201 but got " + status)); - } - }) - .delay(5000) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchNetflixWhenHiddenWithNoPayload.js b/server/tests/js_tests/tests/launchNetflixWhenHiddenWithNoPayload.js deleted file mode 100644 index 3814724..0000000 --- a/server/tests/js_tests/tests/launchNetflixWhenHiddenWithNoPayload.js +++ /dev/null @@ -1,67 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + "Launch Netflix application using DIAL server when app is in hidden state and check for response code 201 "); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function hideApp(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - if(result.state !== "hidden") { - if(result.dialVer && result.dialVer !== "2.1") { // Hidden state not supported - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); - } - - if(result.state === "stopped") { - // Launch and hide app - return dial.launchApplication(host, "Netflix") - .delay(5000) - .then(dial.hideApplication.bind(null, host, "Netflix")) - .delay(5000); - } - else if(result.state === "starting" || result.state === "running") { - // Hide app - return dial.hideApplication(host, "Netflix") - .delay(5000); - } - } - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function checkAppStatus(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - if(result.state !== "hidden") { - return Q.reject(new Error("Expected Netflix app status to be hidden but the status was " + result.state)); - } - }) - - .then(dial.launchApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application when it was in hidden state. Expected statusCode: 201 but got " + status)); - } - }) - .delay(5000) //Allow time for app to launch - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/launchNetflixWhenHiddenWithPayload.js b/server/tests/js_tests/tests/launchNetflixWhenHiddenWithPayload.js deleted file mode 100644 index a574820..0000000 --- a/server/tests/js_tests/tests/launchNetflixWhenHiddenWithPayload.js +++ /dev/null @@ -1,67 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + "Launch Netflix application with payload using DIAL server when app is in hidden state and check for response code 201 "); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function hideApp(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - if(result.state !== "hidden") { - if(result.dialVer && result.dialVer !== "2.1") { // Hidden state not supported - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); - } - - if(result.state === "stopped") { - // Launch and hide app - return dial.launchApplication(host, "Netflix") - .delay(5000) - .then(dial.hideApplication.bind(null, host, "Netflix")) - .delay(5000); - } - else if(result.state === "starting" || result.state === "running") { - // Hide app - return dial.hideApplication(host, "Netflix") - .delay(5000); - } - } - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function checkAppStatus(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - if(result.state !== "hidden") { - return Q.reject(new Error("Expected Netflix app status to be hidden but the status was " + result.state)); - } - }) - - .then(dial.launchApplication.bind(null, host, "Netflix", "key1=val1&key2=val2")) - .then(function (status) { - if(status !== 201) { - return Q.reject(new Error("Error launching Netflix application when it was in hidden state. Expected statusCode: 201 but got " + status)); - } - }) - .delay(5000) //Allow time for app to launch - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/netflixTests.js b/server/tests/js_tests/tests/netflixTests.js deleted file mode 100644 index 2896727..0000000 --- a/server/tests/js_tests/tests/netflixTests.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; - -var Q = require("q"); - -var discoverServerUnderTest = require("../tests/discoverServerUnderTest.js"), - launchInvalidApp = require("../tests/launchAppNotRecognized.js"), - launchNetflixInRunningStateWithNoPayload = require("../tests/launchNetflixAlreadyRunningWithNoPayload.js"), - launchNetflixInRunningStateWithPayload = require("../tests/launchNetflixAlreadyRunningWithPayload.js"), - launchNetflixInStoppedStateWithNoPayload = require("../tests/launchNetflixNotRunningWithNoPayload.js"), - launchNetflixInStoppedStateWithPayload = require("../tests/launchNetflixNotRunningWithPayload.js"), - launchNetflixWhenHiddenWithNoPayload = require("../tests/launchNetflixWhenHiddenWithNoPayload.js"), - launchNetflixWhenHiddenWithPayload = require("../tests/launchNetflixWhenHiddenWithPayload.js"), - launchNetflixWithExcessPayload = require("../tests/launchNetflixWithExcessPayload.js"), - stopInvalidNetflixInstance = require("../tests/stopInvalidNetflixInstance.js"), - stopNetflixInRunningState = require("../tests/stopNetflixInRunningState.js"), - stopNetflixInStoppedState = require("../tests/stopNetflixInStoppedState.js"), - stopNetflixInHiddenState = require("../tests/stopNetflixInHiddenState.js"), - hideInvalidApplicationInstance = require("../tests/hideInvalidApplicationInstance.js"), - hideNetflixWhenAlreadyHidden = require("../tests/hideNetflixWhenAlreadyHidden.js"), - hideNetflixWhenRunning = require("../tests/hideNetflixWhenRunning.js"); - -new Q() - .then(discoverServerUnderTest.test) - .then(launchInvalidApp.test) - .then(launchNetflixInRunningStateWithNoPayload.test) - .then(launchNetflixInRunningStateWithPayload.test) - .then(launchNetflixInStoppedStateWithNoPayload.test) - .then(launchNetflixInStoppedStateWithPayload.test) - .then(launchNetflixWhenHiddenWithNoPayload.test) - .then(launchNetflixWhenHiddenWithPayload.test) - .then(launchNetflixWithExcessPayload.test) - .then(stopInvalidNetflixInstance.test) - .then(stopNetflixInRunningState.test) - .then(stopNetflixInStoppedState.test) - .then(stopNetflixInHiddenState.test) - .then(hideInvalidApplicationInstance.test) - .then(hideNetflixWhenAlreadyHidden.test) - .then(hideNetflixWhenRunning.test) - .done(); diff --git a/server/tests/js_tests/tests/stopApplicationInHiddenState.js b/server/tests/js_tests/tests/stopApplicationInHiddenState.js new file mode 100644 index 0000000..eddc190 --- /dev/null +++ b/server/tests/js_tests/tests/stopApplicationInHiddenState.js @@ -0,0 +1,81 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Stop " + app + " application using DIAL server when the application is in hidden state and expect response code 200"); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function hideApp(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + if(result.state === "stopped") { + // Launch and hide app + return dial.launchApplication(host, app) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state)); + } + }) + .then(dial.hideApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange) + + } + return dial.hideApplication(host, app) + .delay(timeToWaitForStateChange); + } + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "hidden") { + return Q.reject(new Error("Expected " + app + " app state to be hidden but the state was " + result.state)); + } + }) + + .then(dial.stopApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Tried to stop " + app + ". Expected statusCode: 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function checkAppStatus(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "stopped") { + return Q.reject(new Error("Expected " + app + " app state to be stopped but the state was " + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/stopApplicationInRunningState.js b/server/tests/js_tests/tests/stopApplicationInRunningState.js new file mode 100644 index 0000000..13947f4 --- /dev/null +++ b/server/tests/js_tests/tests/stopApplicationInRunningState.js @@ -0,0 +1,73 @@ +"use strict"; + +var dial = require("../libs/dialClient.js"), + utils = require("../libs/utils.js"), + Q = require("q"); + +function test() { + var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; + + return new Q() + .then(function () { + console.log("TEST " + __filename + ": Stop " + app + " application when it is running and check for response code 200 from DIAL server "); + }) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + return result.state; + }) + + .then(function startAppIfNotRunning(state) { + if(state !== "running") { + return dial.launchApplication(host, app) + .then(function (response) { + if(response.statusCode !== 201) { + return Q.reject("Error launching " + app + " application. Expected status code 201 but got " + response.statusCode); + } + }); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " state to be running but querying application state returned " + result.state)); + } + }) + + .then(dial.stopApplication.bind(null, host, app)) + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject("Error stopping " + app + " application. Expected status code 200 but got " + response.statusCode); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Error retrieving current " + app + " application state")); + } + if(result.state !== "stopped") { + return Q.reject(new Error("Expected " + app + " state to be stopped but querying application state returned " + result.state)); + } + }) + .then(function () { + console.log("TEST PASSED"); + }) + .fail(function handleError(err) { + console.error("TEST FAILED " + err); + }); +} + +module.exports.test = test; + +if (require.main === module) { + test.done(); +} diff --git a/server/tests/js_tests/tests/stopNetflixInStoppedState.js b/server/tests/js_tests/tests/stopApplicationInStoppedState.js similarity index 52% rename from server/tests/js_tests/tests/stopNetflixInStoppedState.js rename to server/tests/js_tests/tests/stopApplicationInStoppedState.js index 5f43be3..5bf2464 100644 --- a/server/tests/js_tests/tests/stopNetflixInStoppedState.js +++ b/server/tests/js_tests/tests/stopApplicationInStoppedState.js @@ -6,30 +6,31 @@ var dial = require("../libs/dialClient.js"), function test() { var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; var instanceUrl; return new Q() .then(function () { - console.log("TEST " + __filename + ": Try to stop Netflix application using DIAL server when the application is already stopped and expect response code 200."); + console.log("TEST " + __filename + ": Try to stop " + app + " application using DIAL server when the application is already stopped and expect response code 200."); }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) + .then(dial.getApplicationStatus.bind(null, host, app)) .then(function getCurrentAppState(result) { if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); + return Q.reject(new Error("Could not retrieve current " + app + " application state")); } - if(result.state !== "stopped") { - if(result.allowStop && result.allowStop === "false") { - return Q.reject(new Error("The DIAL server does not support STOP operation. Test cannot proceed. Make sure the Netflix app is stopped before re-running the test")); - } + + if(result.allowStop && result.allowStop === "false") { + return Q.reject(new Error("This test is not applicable for DIAL servers that do not support STOP operation")); } return result.state; }) .then(function getRunningInstanceUrlAndStopApp(state) { if(state !== "stopped") { return new Q() - .then(dial.constructAppResourceUrl.bind(null, host, "Netflix")) + .then(dial.constructAppResourceUrl.bind(null, host, app)) .then(function getInstanceUrl(appResourceUrl) { - return dial.getApplicationStatus(host, "Netflix") + return dial.getApplicationStatus(host, app) .then(function (response) { if(response.href) { instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url @@ -40,13 +41,22 @@ function test() { }); } return new Q() - .then(dial.launchApplication.bind(null, host, "Netflix")) - .delay(5000) + .then(dial.launchApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "running") { + return Q.reject(new Error("Expected " + app + " application state to be running but state was " + result.state)); + } + }) .then(function () { - return dial.constructAppResourceUrl(host, "Netflix"); + return dial.constructAppResourceUrl(host, app); }) .then(function getInstanceUrl(appResourceUrl) { - return dial.getApplicationStatus(host, "Netflix") + return dial.getApplicationStatus(host, app) .then(function (response) { if(response.href) { instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url @@ -60,12 +70,21 @@ function test() { .then(function stopApp() { return dial.stopApplicationInstance(instanceUrl); }) - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Could not stop Netflix application when it was running. Expected status code 200 but got " + status)); + .then(function (response) { + if(response.statusCode !== 200) { + return Q.reject(new Error("Could not stop " + app + " application when it was running. Expected status code 200 but got " + response.statusCode)); + } + }) + .delay(timeToWaitForStateChange) + .then(dial.getApplicationStatus.bind(null, host, app)) + .then(function getCurrentAppState(result) { + if(!result || !result.state) { + return Q.reject(new Error("Could not retrieve current " + app + " application state")); + } + if(result.state !== "stopped") { + return Q.reject(new Error("Expected " + app + " application state to be stopped but state was " + result.state)); } }) - .delay(5000) .then(function () { console.log("TEST PASSED"); }) diff --git a/server/tests/js_tests/tests/stopInvalidNetflixInstance.js b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js similarity index 60% rename from server/tests/js_tests/tests/stopInvalidNetflixInstance.js rename to server/tests/js_tests/tests/stopInvalidApplicationInstance.js index 81fe783..82d4c5a 100644 --- a/server/tests/js_tests/tests/stopInvalidNetflixInstance.js +++ b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js @@ -6,41 +6,43 @@ var dial = require("../libs/dialClient.js"), function test() { var host = utils.getParam("host"); + var app = utils.getParam("app"); + var timeToWaitForStateChange = utils.getParam("timeToWaitForStateChange") || 5000; return new Q() .then(function () { - console.log("TEST " + __filename + ": Try to stop invalid Netflix application instance and check for DIAL server response code 404"); + console.log("TEST " + __filename + ": Try to stop invalid " + app + " application instance and check for DIAL server response code 404"); }) - .then(dial.launchApplication.bind(null, host, "Netflix")) - .delay(5000) + .then(dial.launchApplication.bind(null, host, app)) + .delay(timeToWaitForStateChange) .then(function getCurrentAppState() { - return dial.getApplicationStatus(host, "Netflix") + return dial.getApplicationStatus(host, app) .then(function (result) { if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); + return Q.reject(new Error("Error retrieving current " + app + " application state")); } if(result.allowStop && result.allowStop === "false") { return Q.reject(new Error("This test is not applicable for servers that do not support DIAL stop operation.")); } if(result.state !== "running") { - return Q.reject(new Error("Expected Netflix application to be running but server returned application state as " + result.state)); + return Q.reject(new Error("Expected " + app + " application to be running but server returned application state as " + result.state)); } }); }) - .delay(5000) + .delay(timeToWaitForStateChange) .then(function () { return dial.getAppsUrl(host); }) .then(function (appsUrl) { - var invalidInstanceUrl = appsUrl + "/Netflix/xyz"; + var invalidInstanceUrl = appsUrl + "/" + app + "/xyz"; return invalidInstanceUrl; }) .then(function (url) { return dial.stopApplicationInstance(url); }) - .then(function (status) { - if(status !== 404) { - return Q.reject(new Error("Tried to stop invalid Netflix application instance. Expected statusCode: 404 but got " + status)); + .then(function (response) { + if(response.statusCode !== 404) { + return Q.reject(new Error("Tried to stop invalid " + app + " application instance. Expected statusCode: 404 but got " + response.statusCode)); } }) .then(function () { diff --git a/server/tests/js_tests/tests/stopNetflixInHiddenState.js b/server/tests/js_tests/tests/stopNetflixInHiddenState.js deleted file mode 100644 index 7a217af..0000000 --- a/server/tests/js_tests/tests/stopNetflixInHiddenState.js +++ /dev/null @@ -1,69 +0,0 @@ - -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -function test() { - var host = utils.getParam("host"); - - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Stop Netflix application using DIAL server when the application is in hidden state and expect response code 200"); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function hideApp(result) { - if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); - } - if(result.state !== "hidden") { - if(!result.dialVer || result.dialVer !== "2.1") { // Hidden state not supported - return Q.reject(new Error("This test is only applicable for DIAL version >= 2.1")); - } - - if(result.state === "stopped") { - // Launch and hide app - return dial.launchApplication(host, "Netflix") - .delay(5000) - .then(dial.hideApplication.bind(null, host, "Netflix")) - .delay(5000); - } - else if(result.state === "starting" || result.state === "running") { - // Hide app - return dial.hideApplication(host, "Netflix") - .delay(5000); - } - } - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function checkAppStatus(result) { - if(!result || !result.state) { - return Q.reject(new Error("Could not retrieve current Netflix application state")); - } - if(result.state !== "hidden") { - return Q.reject(new Error("Expected Netflix app status to be hidden but the status was " + result.state)); - } - }) - - .then(dial.stopApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 200) { - return Q.reject(new Error("Tried to stop Netflix. Expected statusCode: 200 but got " + status)); - } - }) - .delay(5000) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/stopNetflixInRunningState.js b/server/tests/js_tests/tests/stopNetflixInRunningState.js deleted file mode 100644 index 41fdcc8..0000000 --- a/server/tests/js_tests/tests/stopNetflixInRunningState.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; - -var dial = require("../libs/dialClient.js"), - utils = require("../libs/utils.js"), - Q = require("q"); - -var host = utils.getParam("host"); - -function test() { - return new Q() - .then(function () { - console.log("TEST " + __filename + ": Stop Netflix application when it is running and check for response code 200 from DIAL server "); - }) - .then(dial.getApplicationStatus.bind(null, host, "Netflix")) - .then(function getCurrentAppState(result) { - if(!result || !result.state) { - return Q.reject(new Error("Error retrieving current Netflix application state")); - } - if(result.allowStop && result.allowStop === "false") { - return Q.reject(new Error("This test is not applicable for servers that do not support DIAL stop operation.")); - } - return result.state; - }) - - .then(function startAppIfNotRunning(state) { - if(state !== "starting" && state !== "running") { - return dial.launchApplication(host, "Netflix") - .then(function (status) { - if(status !== 201) { - return Q.reject("Error launching Netflix application. Expected status code 201 but got " + status); - } - }); - } - }) - .delay(5000) - .then(dial.stopApplication.bind(null, host, "Netflix")) - .then(function (status) { - if(status !== 200) { - return Q.reject("Error stopping Netflix application. Expected status code 200 but got " + status); - } - }) - .then(function () { - console.log("TEST PASSED"); - }) - .fail(function handleError(err) { - console.error("TEST FAILED " + err); - }); -} - -module.exports.test = test; - -if (require.main === module) { - test.done(); -} diff --git a/server/tests/js_tests/tests/tests.js b/server/tests/js_tests/tests/tests.js new file mode 100644 index 0000000..5c21cad --- /dev/null +++ b/server/tests/js_tests/tests/tests.js @@ -0,0 +1,44 @@ +"use strict"; + +var Q = require("q"); + +var discoverServerUnderTest = require("../tests/discoverServerUnderTest.js"), + launchApplicationNotRecognized = require("../tests/launchApplicationNotRecognized.js"), + launchApplicationInRunningStateWithNoPayload = require("../tests/launchApplicationInRunningStateWithNoPayload.js"), + launchApplicationInRunningStateWithPayload = require("../tests/launchApplicationInRunningStateWithPayload.js"), + launchApplicationInStoppedStateWithNoPayload = require("../tests/launchApplicationInStoppedStateWithNoPayload.js"), + launchApplicationInStoppedStateWithPayload = require("../tests/launchApplicationInStoppedStateWithPayload.js"), + launchApplicationInHiddenStateWithNoPayload = require("../tests/launchApplicationInHiddenStateWithNoPayload.js"), + launchApplicationInHiddenStateWithPayload = require("../tests/launchApplicationInHiddenStateWithPayload.js"), + launchApplicationWithExcessPayload = require("../tests/launchApplicationWithExcessPayload.js"), + stopInvalidApplicationInstance = require("../tests/stopInvalidApplicationInstance.js"), + stopApplicationInRunningState = require("../tests/stopApplicationInRunningState.js"), + stopApplicationInStoppedState = require("../tests/stopApplicationInStoppedState.js"), + stopApplicationInHiddenState = require("../tests/stopApplicationInHiddenState.js"), + hideInvalidApplicationInstance = require("../tests/hideInvalidApplicationInstance.js"), + hideApplicationInHiddenState = require("../tests/hideApplicationInHiddenState.js"), + hideApplicationInRunningState = require("../tests/hideApplicationInRunningState.js"); + +new Q() + .then(discoverServerUnderTest.test) + // Application launch tests + .then(launchApplicationNotRecognized.test) + .then(launchApplicationInRunningStateWithNoPayload.test) + .then(launchApplicationInRunningStateWithPayload.test) + .then(launchApplicationInStoppedStateWithNoPayload.test) + .then(launchApplicationInStoppedStateWithPayload.test) + .then(launchApplicationInHiddenStateWithNoPayload.test) + .then(launchApplicationInHiddenStateWithPayload.test) + .then(launchApplicationWithExcessPayload.test) + + // Application stop tests + .then(stopInvalidApplicationInstance.test) + .then(stopApplicationInRunningState.test) + .then(stopApplicationInStoppedState.test) + .then(stopApplicationInHiddenState.test) + + // Application hide tests + .then(hideInvalidApplicationInstance.test) + .then(hideApplicationInHiddenState.test) + .then(hideApplicationInRunningState.test) + .done();