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

View File

@@ -1,9 +1,10 @@
"use strict";
const colors = require("colors/safe");
const sprintf = require("sprintf-js").sprintf;
const winston = require("winston");
const moment = require("moment");
const colors = require("colors/safe");
const sprintf = require("sprintf-js").sprintf;
const winston = require("winston");
const moment = require("moment");
const keypress = require("keypress");
const levels = { error: 0, warn: 1, info: 2, verbose: 3, debug: 4 };
const transports = [
@@ -14,7 +15,7 @@ const transports = [
new (winston.transports.File)({
level: "debug",
name: "log_file",
filename: "log.txt",
filename: "js_tests_log.txt",
json: false,
formatter: fileFormatter,
options: { flags: "w" }
@@ -41,6 +42,29 @@ function fileFormatter(options) {
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) {
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));

View File

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

View File

@@ -34,59 +34,89 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
utils.printDebug("Application status is " + result.state);
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
if(result.state === "stopped") {
// Launch and hide app
return dial.launchApplication(host, app)
return new Q()
.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)
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
utils.printDebug("Application status is " + result.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 state was " + result.state));
}
})
.then(function () {
utils.printDebug("Hide application ..");
utils.printDebug("Hiding application ..");
})
.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()
.then(function () {
utils.printDebug("Hide application ..");
utils.printDebug("Hiding application ..");
return dial.hideApplication(host, app);
})
.delay(timeToWaitForStateChange);
}
})
.then(function () {
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 status is now " + result.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 () {
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));
}
})
}
})
.then(function () {
utils.printDebug("Hide application ..");
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app))
.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));
}
})
.delay(timeToWaitForStateChange)
.then(dial.getApplicationStatus.bind(null, host, app))
.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 status is " + 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));
}

View File

@@ -19,7 +19,7 @@ const argv = require("yargs")
})
.option("timeToWaitForStateChange", {
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",
default: 5000
})
@@ -34,6 +34,9 @@ function test() {
.then(function () {
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(function getCurrentAppState(result) {
if(!result || !result.state) {
@@ -43,38 +46,60 @@ function test() {
})
.then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
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) {
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(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change to happen");
})
.delay(timeToWaitForStateChange)
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
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(function (response) {
if(response.statusCode !== 200) {
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)
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
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 () {
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(function hideApp(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") {
if(result.state === "stopped") {
// 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)
.then(function () {
utils.printDebug("Querying application status ..");
})
.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"));
}
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 () {
utils.printDebug("Hiding application ..");
})
.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
return dial.hideApplication(host, app)
.delay(timeToWaitForStateChange);
}
}
})
.then(function () {
return dial.getApplicationStatus(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));
// 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 ..");
})
.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));
}
})
.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 !== "running") {
return Q.reject(new Error("Expected " + app + " app status to be running but the status was " + result.state));
}
})
.then(function () {
utils.printTestSuccess()
})

View File

@@ -34,54 +34,115 @@ function test() {
.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 ");
})
.then(function () {
utils.printDebug("Querying application status ..");
})
.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"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
if(result.state === "stopped") {
// 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)
.then(function () {
utils.printDebug("Querying application status ..");
})
.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"));
}
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 () {
utils.printDebug("Hiding application ..");
})
.then(dial.hideApplication.bind(null, host, app))
.delay(timeToWaitForStateChange);
}
else {
// Hide app
return dial.hideApplication(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));
}
});
}
// 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 () {
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"));
}
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app status to be hidden but the status was " + result.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(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 () {
utils.printTestSuccess()
})

View File

@@ -34,6 +34,9 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
@@ -43,43 +46,61 @@ function test() {
})
.then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
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) {
if(response.statusCode !== 201) {
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(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 () {
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));
}
})
.then(function () {
utils.printTestSuccess()
})

View File

@@ -34,6 +34,9 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
if(!result || !result.state) {
@@ -43,44 +46,61 @@ function test() {
})
.then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
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) {
if(response.statusCode !== 201) {
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 () {
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)
})
.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));
}
})
.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 () {
utils.printTestSuccess()
})

View File

@@ -34,30 +34,43 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) {
if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state");
}
utils.printDebug("Application is in " + result.state + " 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)
return new Q()
.then(function () {
utils.printDebug("Stopping application ..");
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));
}
})
.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 checkAppState(result) {
if(!result || !result.state) {
return Q.reject("Error retrieving " + 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 querying for state returned " + result.state));
}
@@ -66,20 +79,28 @@ function test() {
return result.state;
})
.then(function () {
utils.printDebug("Launching application ..");
})
.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));
}
})
.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));
}

View File

@@ -34,30 +34,43 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state ..");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) {
if(!result || !result.state) {
return Q.reject("Error retrieving " + app + " application state");
}
utils.printDebug("Application is in " + result.state + " 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. " +
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)
return new Q()
.then(function () {
utils.printDebug("Stopping application ..");
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));
}
})
.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 checkAppState(result) {
if(!result || !result.state) {
return Q.reject("Error retrieving " + 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 querying for state returned " + result.state));
}
@@ -66,20 +79,28 @@ function test() {
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) {
if(response.statusCode !== 201) {
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)
.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));
}

View File

@@ -34,59 +34,110 @@ function test() {
.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");
})
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
utils.printDebug("Application is in " + result.state + " state");
if(result.state !== "hidden") {
if(result.state === "stopped") {
// 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)
.then(function () {
utils.printDebug("Querying application state ..");
})
.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"));
}
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(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
})
.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)
.delay(timeToWaitForStateChange);
}
})
.then(function () {
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"));
}
if(result.state !== "hidden") {
return Q.reject(new Error("Expected " + app + " app state to be hidden but the state was " + result.state));
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");
})
.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));
}
});
}
})
.then(function () {
utils.printDebug("Stopping application ..");
})
.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));
}
})
.then(function () {
utils.printDebug("Wait for " + timeToWaitForStateChange + " ms for state change");
})
.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 !== "stopped") {
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 () {
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(function getCurrentAppState(result) {
if(!result || !result.state) {
@@ -43,42 +46,60 @@ function test() {
})
.then(function startAppIfNotRunning(state) {
utils.printDebug("Application is in " + state + " state");
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) {
if(response.statusCode !== 201) {
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(function (response) {
if(response.statusCode !== 200) {
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)
.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 !== "stopped") {
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()
.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(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.allowStop && result.allowStop === "false") {
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) {
if(response.href) {
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()
.then(function () {
utils.printDebug("Launching application ..");
})
.then(dial.launchApplication.bind(null, 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 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 !== "running") {
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) {
if(response.href) {
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() {
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));
if(response.statusCode !== 404) {
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 () {
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 () {
utils.printTestSuccess()
})