adding logging for js tests

This commit is contained in:
Shruti Ranganathan Jothi
2017-03-08 19:30:02 -08:00
parent b0061b88ad
commit 1f5c5454f2
15 changed files with 579 additions and 151 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ server/dialserver
server/tests/run_tests server/tests/run_tests
client/report.html client/report.html
node_modules/ node_modules/
js_tests_log.txt

4
README
View File

@@ -120,5 +120,5 @@ Options:
--application, --app Application to test [string] [required] --application, --app Application to test [string] [required]
--help, -h Show help [boolean] --help, -h Show help [boolean]
Log file of test run is written in log.txt in the server/tests/js_tests/tests Log file of test run is written in js_tests_log.txt in the
folder. server/tests/js_tests/tests folder.

View File

@@ -1,9 +1,10 @@
"use strict"; "use strict";
const colors = require("colors/safe"); const colors = require("colors/safe");
const sprintf = require("sprintf-js").sprintf; const sprintf = require("sprintf-js").sprintf;
const winston = require("winston"); const winston = require("winston");
const moment = require("moment"); const moment = require("moment");
const keypress = require("keypress");
const levels = { error: 0, warn: 1, info: 2, verbose: 3, debug: 4 }; const levels = { error: 0, warn: 1, info: 2, verbose: 3, debug: 4 };
const transports = [ const transports = [
@@ -14,7 +15,7 @@ const transports = [
new (winston.transports.File)({ new (winston.transports.File)({
level: "debug", level: "debug",
name: "log_file", name: "log_file",
filename: "log.txt", filename: "js_tests_log.txt",
json: false, json: false,
formatter: fileFormatter, formatter: fileFormatter,
options: { flags: "w" } options: { flags: "w" }
@@ -41,6 +42,29 @@ function fileFormatter(options) {
return str; return str;
} }
function ask(description) {
return new Q.Promise(function (resolve, reject) {
// make `process.stdin` begin emitting "keypress" events
keypress(process.stdin);
process.stdin.setRawMode(true);
process.stdin.resume();
console.log(description);
// listen for the "keypress" event
process.stdin.on("keypress", function (ch, key) {
if (key && key.name === "return") {
process.stdin.pause();
return resolve();
}
if (key && key.name === "backspace") {
process.stdin.pause();
return reject("User marked the step as FAILED");
}
});
});
}
function printTestInfo(testFile, description) { function printTestInfo(testFile, description) {
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "TEST", testFile)); winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "TEST", testFile));
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DESCRIPTION", description)); winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DESCRIPTION", description));

View File

@@ -12,6 +12,7 @@
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"dependencies": { "dependencies": {
"colors": "^1.1.2", "colors": "^1.1.2",
"keypress": "^0.2.1",
"moment": "^2.17.1", "moment": "^2.17.1",
"node-ssdp": "^3.2.0", "node-ssdp": "^3.2.0",
"q": "~1.4.1", "q": "~1.4.1",

View File

@@ -34,59 +34,89 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to hide " + app + " when it is already in hidden state and expect response code 200 from the DIAL server"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to hide " + app + " when it is already in hidden state and expect response code 200 from the DIAL server");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) { .then(function hideApp(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application status is " + result.state); utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
if(result.state === "stopped") { if(result.state === "stopped") {
// Launch and hide app // Launch and hide app
return dial.launchApplication(host, app) return new Q()
.then(function () { .then(function () {
utils.printDebug("Requested server to launch application .."); utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
}) })
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application status is " + result.state); utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " app status to be running but the state was " + result.state)); return Q.reject(new Error("Expected " + app + " app status to be running but the state was " + result.state));
} }
}) })
.then(function () { .then(function () {
utils.printDebug("Hide application .."); utils.printDebug("Hiding application ..");
}) })
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.delay(timeToWaitForStateChange); .then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
}
})
} }
return new Q() return new Q()
.then(function () { .then(function () {
utils.printDebug("Hide application .."); utils.printDebug("Hiding application ..");
return dial.hideApplication(host, app); return dial.hideApplication(host, app);
}) })
.delay(timeToWaitForStateChange); .then(function () {
} utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
}) })
.then(function () { .delay(timeToWaitForStateChange)
return dial.getApplicationStatus(host, app) .then(function () {
}) utils.printDebug("Querying application state ..");
.then(function checkAppStatus(result) { return dial.getApplicationStatus(host, app)
if(!result || !result.state) { })
return Q.reject(new Error("Could not retrieve current " + app + " application state")); .then(function checkAppStatus(result) {
} if(!result || !result.state) {
utils.printDebug("Application status is now " + 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)); utils.printDebug("Application is in " + result.state + " 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 () { .then(function () {
utils.printDebug("Hide application .."); utils.printDebug("Hiding application ..");
}) })
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
@@ -94,13 +124,15 @@ function test() {
return Q.reject(new Error("Tried to hide " + app + ". Expected statusCode: 200 but got " + response.statusCode)); return Q.reject(new Error("Tried to hide " + app + ". Expected statusCode: 200 but got " + response.statusCode));
} }
}) })
.delay(timeToWaitForStateChange) .then(function () {
.then(dial.getApplicationStatus.bind(null, host, app)) utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application status is " + result.state); utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state)); return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
} }

View File

@@ -19,7 +19,7 @@ const argv = require("yargs")
}) })
.option("timeToWaitForStateChange", { .option("timeToWaitForStateChange", {
alias: "ttw", alias: "ttw",
describe: "Time(ms) to wait between state changes before querying application status", describe: "Time(ms) to wait between state changes before Querying application state",
type: "string", type: "string",
default: 5000 default: 5000
}) })
@@ -34,6 +34,9 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Hide " + app + " application when it is running and expect response code 200"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Hide " + app + " application when it is running and expect response code 200");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
@@ -43,38 +46,60 @@ function test() {
}) })
.then(function startAppIfNotRunning(state) { .then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
if(state !== "running") { if(state !== "running") {
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject(new Error("Could not launch " + app + " application. Expected status code 201 but got " + response.statusCode)); return Q.reject(new Error("Could not launch " + app + " application. Expected status code 201 but got " + response.statusCode));
} }
}); })
} .then(function () {
}) utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
.delay(timeToWaitForStateChange) })
.then(dial.getApplicationStatus.bind(null, host, app)) .delay(timeToWaitForStateChange)
.then(function getCurrentAppState(result) { .then(function () {
if(!result || !result.state) { utils.printDebug("Querying application state ..");
return Q.reject(new Error("Could not retrieve current " + app + " application state")); })
} .then(dial.getApplicationStatus.bind(null, host, app))
if(result.state !== "running") { .then(function getCurrentAppState(result) {
return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state)); if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state));
}
})
} }
}) })
.then(function () {
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { if(response.statusCode !== 200) {
return Q.reject(new Error("Error hiding " + app + " application. Expected status code 200 but got " + response.statusCode)); return Q.reject(new Error("Error hiding " + app + " application. Expected status code 200 but got " + response.statusCode));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " state to be hidden but state was " + result.state)); return Q.reject(new Error("Expected " + app + " state to be hidden but state was " + result.state));
} }

View File

@@ -34,54 +34,115 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when app is in hidden state and check for response code 201 "); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when app is in hidden state and check for response code 201 ");
}) })
.then(function () {
utils.printDebug("Querying application status ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) { .then(function hideApp(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
if(result.state === "stopped") { if(result.state === "stopped") {
// Launch and hide app // Launch and hide app
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application status ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state)); return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state));
} }
}) })
.then(function () {
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.delay(timeToWaitForStateChange); .then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state));
}
});
} }
else { // Hide app
// Hide app return new Q()
return dial.hideApplication(host, app) .then(function () {
.delay(timeToWaitForStateChange); utils.printDebug("Hiding application ..");
} return dial.hideApplication(host, app);
} })
}) .then(function () {
.then(function () { utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
return dial.getApplicationStatus(host, app) })
}) .delay(timeToWaitForStateChange)
.then(function checkAppStatus(result) { .then(function () {
if(!result || !result.state) { utils.printDebug("Querying application state ..");
return Q.reject(new Error("Error retrieving current " + app + " application state")); return dial.getApplicationStatus(host, app)
} })
if(result.state !== "hidden") { .then(function checkAppStatus(result) {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state)); if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state));
}
});
} }
}) })
.then(function () {
utils.printDebug("Launching application ..");
})
.then(dial.launchApplication.bind(null, host, app)) .then(dial.launchApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { 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)); return Q.reject(new Error("Error launching " + app + " application when it was in hidden state. Expected statusCode: 201 but got " + response.statusCode));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state));
}
})
.then(function () { .then(function () {
utils.printTestSuccess() utils.printTestSuccess()
}) })

View File

@@ -34,54 +34,115 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when app is in hidden state and check for response code 201 "); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when app is in hidden state and check for response code 201 ");
}) })
.then(function () {
utils.printDebug("Querying application status ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) { .then(function hideApp(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
if(result.state === "stopped") { if(result.state === "stopped") {
// Launch and hide app // Launch and hide app
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application status ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state)); return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state));
} }
}) })
.then(function () {
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.delay(timeToWaitForStateChange); .then(function () {
} utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
else { })
// Hide app .delay(timeToWaitForStateChange)
return dial.hideApplication(host, app) .then(function () {
.delay(timeToWaitForStateChange); utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state));
}
});
} }
// Hide app
return new Q()
.then(function () {
utils.printDebug("Hiding application ..");
return dial.hideApplication(host, app);
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.state));
}
});
}
})
.then(function () {
utils.printDebug("Launching application with payload..");
})
.then(dial.launchApplication.bind(null, host, app, "key1=val1&key2=val2"))
.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));
} }
}) })
.then(function () { .then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
if(result.state !== "hidden") { utils.printDebug("Application is in " + result.state + " state");
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.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.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 () { .then(function () {
utils.printTestSuccess() utils.printTestSuccess()
}) })

View File

@@ -34,6 +34,9 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " without payload using DIAL server when application is already running and check for response code 201"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " without payload using DIAL server when application is already running and check for response code 201");
}) })
.then(function () {
utils.printDebug("Querying application state");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
@@ -43,43 +46,61 @@ function test() {
}) })
.then(function startAppIfNotRunning(state) { .then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
if(state !== "running") { if(state !== "running") {
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode)); return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode));
} }
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " 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));
}
}); });
} }
}) })
.delay(timeToWaitForStateChange)
.then(function () {
return dial.getApplicationStatus(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 () {
utils.printDebug("Launching application ..");
})
.then(dial.launchApplication.bind(null, host, app)) .then(dial.launchApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { 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)); 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 () {
utils.printDebug("Querying application state");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { 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)); return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state));
} }
}) })
.then(function () { .then(function () {
utils.printTestSuccess() utils.printTestSuccess()
}) })

View File

@@ -34,6 +34,9 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " with payload using DIAL server when application is already running and check for response code 201"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " with payload using DIAL server when application is already running and check for response code 201");
}) })
.then(function () {
utils.printDebug("Querying application state");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
@@ -43,44 +46,61 @@ function test() {
}) })
.then(function startAppIfNotRunning(state) { .then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
if(state !== "running") { if(state !== "running") {
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode)); return Q.reject(new Error("Error launching " + app + " application. Expected status code 201 from DIAL server but got " + response.statusCode));
} }
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " 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));
}
}); });
} }
}) })
.delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Launching application with payload..");
})
.then(dial.launchApplication.bind(null, host, app, "key1=val1&key2=val2"))
.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(function () {
utils.printDebug("Querying application state");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { 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)); 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 () { .then(function () {
utils.printTestSuccess() utils.printTestSuccess()
}) })

View File

@@ -34,30 +34,43 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when the application is in STOPPED state and expect response code 201"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when the application is in STOPPED state and expect response code 201");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) { .then(function stopAppIfNecessary(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state"); return Q.reject("Error retrieving " + app + " application state");
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
if(!result.href) { 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. " + 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")); "Test cannot proceed. Stop the " + app + " app manually before re-running this test"));
} }
return dial.stopApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Stopping application ..");
return dial.stopApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { 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)); 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));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function checkAppState(result) { .then(function checkAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state"); return Q.reject("Error retrieving " + app + " application state");
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state)); return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state));
} }
@@ -66,20 +79,28 @@ function test() {
return result.state; return result.state;
}) })
.then(function () {
utils.printDebug("Launching application ..");
})
.then(dial.launchApplication.bind(null, host, app)) .then(dial.launchApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode)); return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { 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)); return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state));
} }

View File

@@ -34,30 +34,43 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when the application is in STOPPED state and expect response code 201"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when the application is in STOPPED state and expect response code 201");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) { .then(function stopAppIfNecessary(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state"); return Q.reject("Error retrieving " + app + " application state");
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
if(!result.href) { 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. " + 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")); "Test cannot proceed. Stop the " + app + " app manually before re-running this test"));
} }
return dial.stopApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Stopping application ..");
return dial.stopApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { 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)); 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));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function checkAppState(result) { .then(function checkAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state"); return Q.reject("Error retrieving " + app + " application state");
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state)); return Q.reject(new Error("Expected " + app + " application state to be stopped but querying for state returned " + result.state));
} }
@@ -66,20 +79,28 @@ function test() {
return result.state; return result.state;
}) })
.then(dial.launchApplication.bind(null, host, app, "key1=val1")) .then(function () {
utils.printDebug("Launching application with payload..");
})
.then(dial.launchApplication.bind(null, host, app, "key1=val1&key2=val2"))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode)); return Q.reject(new Error("Error launching " + app + " application. Expected statusCode: 201 but got " + response.statusCode));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { 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)); return Q.reject(new Error("Expected " + app + " application to be in running state, but querying state returned state as" + result.state));
} }

View File

@@ -34,59 +34,110 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application using DIAL server when the application is in hidden state and expect response code 200"); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application using DIAL server when the application is in hidden state and expect response code 200");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) { .then(function hideApp(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") { if(result.state !== "hidden") {
if(result.state === "stopped") { if(result.state === "stopped") {
// Launch and hide app // Launch and hide app
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getAppState(result) { .then(function getAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state)); return Q.reject(new Error("Expected " + app + " state to be running but state was " + result.state));
} }
}) })
.then(function () {
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app)) .then(dial.hideApplication.bind(null, host, app))
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app state to be hidden but the state was " + result.state));
}
})
} }
return dial.hideApplication(host, app) return new Q()
.delay(timeToWaitForStateChange); .then(function () {
} utils.printDebug("Hiding application ..");
}) return dial.hideApplication(host, app);
.then(function () { })
return dial.getApplicationStatus(host, app) .then(function () {
}) utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
.then(function checkAppStatus(result) { })
if(!result || !result.state) { .delay(timeToWaitForStateChange)
return Q.reject(new Error("Could not retrieve current " + app + " application state")); .then(function () {
} utils.printDebug("Querying application state ..");
if(result.state !== "hidden") { return dial.getApplicationStatus(host, app)
return Q.reject(new Error("Expected " + app + " app state to be hidden but the state was " + result.state)); })
.then(function checkAppStatus(result) {
if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app state to be hidden but the state was " + result.state));
}
});
} }
}) })
.then(function () {
utils.printDebug("Stopping application ..");
})
.then(dial.stopApplication.bind(null, host, app)) .then(dial.stopApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { if(response.statusCode !== 200) {
return Q.reject(new Error("Tried to stop " + app + ". Expected statusCode: 200 but got " + response.statusCode)); return Q.reject(new Error("Tried to stop " + app + ". Expected statusCode: 200 but got " + response.statusCode));
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function checkAppStatus(result) { .then(function checkAppStatus(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " app state to be stopped but the state was " + result.state)); return Q.reject(new Error("Expected " + app + " app state to be stopped but the state was " + result.state));
} }

View File

@@ -34,6 +34,9 @@ function test() {
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application when it is running and check for response code 200 from DIAL server "); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application when it is running and check for response code 200 from DIAL server ");
}) })
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
@@ -43,42 +46,60 @@ function test() {
}) })
.then(function startAppIfNotRunning(state) { .then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
if(state !== "running") { if(state !== "running") {
return dial.launchApplication(host, app) return new Q()
.then(function () {
utils.printDebug("Launching application ..");
return dial.launchApplication(host, app);
})
.then(function (response) { .then(function (response) {
if(response.statusCode !== 201) { if(response.statusCode !== 201) {
return Q.reject("Error launching " + app + " application. Expected status code 201 but got " + response.statusCode); return Q.reject("Error launching " + app + " application. Expected status code 201 but got " + response.statusCode);
} }
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " state to be running but querying application state returned " + result.state));
}
}); });
} }
}) })
.delay(timeToWaitForStateChange)
.then(function () {
return dial.getApplicationStatus(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(function () {
utils.printDebug("Stopping application ..");
})
.then(dial.stopApplication.bind(null, host, app)) .then(dial.stopApplication.bind(null, host, app))
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { if(response.statusCode !== 200) {
return Q.reject("Error stopping " + app + " application. Expected status code 200 but got " + response.statusCode); return Q.reject("Error stopping " + app + " application. Expected status code 200 but got " + response.statusCode);
} }
}) })
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Error retrieving current " + app + " application state")); return Q.reject(new Error("Error retrieving current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " state to be stopped but querying application state returned " + result.state)); return Q.reject(new Error("Expected " + app + " state to be stopped but querying application state returned " + result.state));
} }

View File

@@ -33,14 +33,18 @@ function test() {
return new Q() return new Q()
.then(function () { .then(function () {
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to stop " + app + " application using DIAL server when the application is already stopped and expect response code 200."); utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to stop " + app + " application using DIAL server when the application "
+ "is already stopped and expect response code 404.");
})
.then(function () {
utils.printDebug("Querying application state ..");
}) })
.then(dial.getApplicationStatus.bind(null, host, app)) .then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.allowStop && result.allowStop === "false") { 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 Q.reject(new Error("This test is not applicable for DIAL servers that do not support STOP operation"));
} }
@@ -55,22 +59,57 @@ function test() {
.then(function (response) { .then(function (response) {
if(response.href) { if(response.href) {
instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url
return instanceUrl;
} }
return Q.reject(new Error("Could not get instance href from application status to construct Application Instance Url")); else {
return Q.reject(new Error("Could not get instance href from application status to construct Application Instance Url"));
}
}); });
})
.then(function stopApp() {
utils.printDebug("Stopping application ..");
return dial.stopApplicationInstance(instanceUrl);
})
.then(function (response) {
if(response.statusCode !== 200) {
return Q.reject(new Error("Could not stop " + app + " application. Expected status code 200 but got " + response.statusCode));
}
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " application state to be stopped but state was " + result.state));
}
}); });
} }
return new Q() return new Q()
.then(function () {
utils.printDebug("Launching application ..");
})
.then(dial.launchApplication.bind(null, host, app)) .then(dial.launchApplication.bind(null, host, app))
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange) .delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "running") { if(result.state !== "running") {
return Q.reject(new Error("Expected " + app + " application state to be running but state was " + result.state)); return Q.reject(new Error("Expected " + app + " application state to be running but state was " + result.state));
} }
@@ -83,33 +122,62 @@ function test() {
.then(function (response) { .then(function (response) {
if(response.href) { if(response.href) {
instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url instanceUrl = appResourceUrl + "/" + response.href; // Construct Application Instance Url
return instanceUrl;
} }
return Q.reject(new Error("Could not get instance href from application status to construct Application Instance Url")); else {
return Q.reject(new Error("Could not get instance href from application status to construct Application Instance Url"));
}
}); });
})
.then(function stopApp() {
utils.printDebug("Stopping application ..");
return dial.stopApplicationInstance(instanceUrl);
})
.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));
}
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app)
})
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " application state to be stopped but state was " + result.state));
}
}); });
}) })
.then(function stopApp() { .then(function stopApp() {
utils.printDebug("Stopping application ..");
return dial.stopApplicationInstance(instanceUrl); return dial.stopApplicationInstance(instanceUrl);
}) })
.then(function (response) { .then(function (response) {
if(response.statusCode !== 200) { if(response.statusCode !== 404) {
return Q.reject(new Error("Could not stop " + app + " application when it was running. Expected status code 200 but got " + response.statusCode)); return Q.reject(new Error("Trying to stop " + app + " application when it is already stopped. Expected status code 404 but got " + response.statusCode));
} }
}) })
.delay(timeToWaitForStateChange)
.then(function () { .then(function () {
utils.printDebug("Querying application state ..");
return dial.getApplicationStatus(host, app) return dial.getApplicationStatus(host, app)
}) })
.then(function getCurrentAppState(result) { .then(function getCurrentAppState(result) {
if(!result || !result.state) { if(!result || !result.state) {
return Q.reject(new Error("Could not retrieve current " + app + " application state")); return Q.reject(new Error("Could not retrieve current " + app + " application state"));
} }
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "stopped") { if(result.state !== "stopped") {
return Q.reject(new Error("Expected " + app + " application state to be stopped but state was " + result.state)); return Q.reject(new Error("Expected " + app + " application state to be stopped but state was " + result.state));
} }
}) })
.then(function () { .then(function () {
utils.printTestSuccess() utils.printTestSuccess()
}) })