/*!
GPII Cloud-based Flow Manager Test Infrastructure
Copyright 2012 OCAD University
Copyright 2012 Antranig Basman
Copyright 2013 Raising the Floor
Copyright 2014 Lucendo Development Ltd.
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
The research leading to these results has received funding from the European Union's
Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii"),
jqUnit = fluid.registerNamespace("jqUnit"),
kettle = fluid.registerNamespace("kettle");
fluid.registerNamespace("gpii.test.cloudBased");
gpii.test.cloudBased.FMRequestListenerMaker = function (expected) {
return function (data) {
jqUnit.assertDeepEq("Checking the returned data from the flowmanager: ", expected, JSON.parse(data));
};
};
gpii.test.cloudBased.computeDevice = function (solutionIds, OSid) {
var device = {
OS: {
id: OSid || "web"
},
solutions: []
};
fluid.each(solutionIds, function (solutionId) {
device.solutions.push({ id: solutionId });
});
return JSON.stringify(device);
};
fluid.defaults("gpii.test.cloudBased.testCaseHolder", {
gradeNames: ["kettle.test.testCaseHolder"],
components: {
fmrequest: {
type: "kettle.test.request.http",
options: {
path: "/%userToken/settings/%device",
port: 8081,
termMap: {
userToken: "{testCaseHolder}.options.userToken",
device: {
expander: {
func: "gpii.test.cloudBased.computeDevice",
args: [["{testCaseHolder}.options.solutionId"], "{testCaseHolder}.options.OSid"]
}
}
}
}
}
}
});
gpii.test.cloudBased.gpiiConfig = function () {
return {
configName: "gpii.tests.acceptance.cloudBased.config.base",
configPath: "%gpii-universal/tests/platform/cloud/configs"
};
};
gpii.test.cloudBased.buildTestFixture = function (testDef) {
// Since we modify the testDef object, we make a copy of it to not screw up any other tests that
// might be sharing the same testDef
testDef = fluid.copy(testDef);
testDef.expect = 1;
testDef.sequence = fluid.makeArray(testDef.sequence);
testDef.gradeNames = fluid.makeArray(testDef.gradeNames);
testDef.gradeNames.push("gpii.test.cloudBased.testCaseHolder");
testDef.sequence.unshift({
func: "{fmrequest}.send"
}, {
event: "{fmrequest}.events.onComplete",
listenerMaker: "gpii.test.cloudBased.FMRequestListenerMaker",
makerArgs: ["{testCaseHolder}.options.expected"]
});
testDef.config = testDef.config || gpii.test.cloudBased.gpiiConfig();
return testDef;
};
gpii.test.cloudBased.bootstrap = function (testDefs) {
return kettle.test.bootstrapServer(testDefs, function (testDef) {
return gpii.test.cloudBased.buildTestFixture(testDef);
});
};
|