Last active
August 29, 2015 14:07
-
-
Save amb26/9f2ace64b6baa125d95d to your computer and use it in GitHub Desktop.
Advice throughout the system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* GPII Integration Testing | |
* | |
* Copyright 2013 Raising the Floor International | |
* Copyright 2013 OCAD University | |
* Copyright 2014 Lucendo Development Ltd. | |
* | |
* Licensed under the New BSD license. You may not use this file except in | |
* compliance with this License. | |
* | |
* You may obtain a copy of the License at | |
* https://github.com/gpii/universal/LICENSE.txt | |
* | |
*/ | |
"use strict"; | |
var fluid = require("infusion"), | |
gpii = fluid.registerNamespace("gpii"); | |
// Maintains a mock model of currently executing processes | |
fluid.defaults("gpii.test.integration.exec", { | |
gradeNames: ["gpii.test.common.exec", "autoInit"], | |
members: { | |
processModel: [] // list of process objects | |
}, | |
invokers: { | |
exec: { | |
funcName: "gpii.test.integration.exec.exec", | |
args: ["{that}", "{arguments}.0", "{arguments}.1"] | |
} | |
} | |
}); | |
gpii.test.integration.exec.exec = function (that, processSpec, expected) { | |
that.events.onExecExit.fire(true, processSpec); | |
}; | |
fluid.defaults("gpii.test.integration.testCaseHolder", { | |
gradeNames: ["gpii.test.common.testCaseHolder", "autoInit"], | |
distributeOptions: [{ | |
record: { | |
funcName: null, | |
func: "{gpii.test.integration.testCaseHolder}.nameResolver.resolveName" | |
}, | |
target: "{that lifecycleManager > nameResolver}.options.invokers.resolveName" | |
}, { | |
record: { | |
funcName: null, | |
func: "{gpii.test.integration.testCaseHolder}.mockPlatformReporter.reportPlatform" | |
}, | |
target: "{that deviceReporter platformReporter}.options.invokers.reportPlatform" | |
}], | |
components: { | |
exec: { | |
type: "gpii.test.integration.exec" | |
}, | |
mockSettingsHandlers: { | |
type: "gpii.test.integration.mockSettingsHandlerRegistry.universal" | |
}, | |
nameResolver: { | |
type: "fluid.littleComponent", | |
options: { | |
invokers: { | |
resolveName: { | |
funcName: "gpii.test.integration.resolveName", | |
args: ["{mockSettingsHandlers}", "{arguments}.0", "{arguments}.1"] | |
} | |
} | |
} | |
} | |
} | |
}); | |
fluid.defaults("gpii.test.integration.testCaseHolder.windows", { | |
components: { | |
mockSettingsHandlers: { | |
type: "gpii.test.integration.mockSettingsHandlerRegistry.windows" | |
}, | |
mockPlatformReporter: { | |
type: "gpii.test.integration.mockPlatformReporter", | |
options: { | |
platform: { | |
id: "win32", | |
version: "6.1.7601" | |
} | |
} | |
} | |
} | |
}); | |
fluid.defaults("gpii.test.integration.testCaseHolder.linux", { | |
components: { | |
mockSettingsHandlers: { | |
type: "gpii.test.integration.mockSettingsHandlerRegistry.linux" | |
}, | |
mockPlatformReporter: { | |
type: "gpii.test.integration.mockPlatformReporter", | |
options: { | |
platform: { | |
id: "linux", | |
version: "2.6.26" | |
} | |
} | |
} | |
} | |
}); | |
fluid.defaults("gpii.test.integration.mockPlatformReporter", { | |
gradeNames: ["fluid.littleComponent", "autoInit"], | |
invokers: { | |
reportPlatform: { | |
funcName: "fluid.identity", | |
args: "{that}.options.platform" | |
} | |
} | |
}); | |
gpii.test.integration.mockExecHandler = function (command, args) { | |
// TODO: we should record the executing process in a process model - ideally we should have a more reliable model of extracting what it is | |
fluid.log("Mock exec handler for command ", command, " args ", args); | |
}; | |
fluid.defaults("gpii.test.integration.mockExecHandler", { | |
gradeNames: "fluid.function", | |
argumentMap: { | |
command: 0, | |
args: 1 | |
} | |
}); | |
gpii.test.integration.resolveName = function (settingsHandlerRegistry, name, category) { | |
if (category === "settingsHandler") { | |
return settingsHandlerRegistry.resolveName(name); | |
} else { | |
return "gpii.test.integration.mockExecHandler" | |
} | |
}; | |
// cf. much less sophisticated mock in LifecycleManagerTest.js | |
fluid.defaults("gpii.test.integration.mockSettingsHandler", { | |
gradeNames: ["fluid.littleComponent", "autoInit"], | |
members: { | |
settingsStore: {} | |
}, | |
async: false, | |
// must be configured for each settingsHandler instance to resolve to a path within | |
// the options structure which determines a unique key for the particular payload | |
// can also resolve to a function which returns such a key given the options | |
optionsPathKey: null, | |
invokers: { | |
set: { | |
funcName: "gpii.test.integration.mockSettingsHandler.set", | |
args: ["{that}", "{arguments}.0"] | |
}, | |
setImpl: { | |
funcName: "gpii.test.integration.mockSettingsHandler.setImpl", | |
args: ["{that}", "{arguments}.0"] | |
}, | |
get: { | |
funcName: "gpii.test.integration.mockSettingsHandler.get", | |
args: ["{that}", "{arguments}.0"] | |
}, | |
getImpl: { | |
funcName: "gpii.test.integration.mockSettingsHandler.getImpl", | |
args: ["{that}", "{arguments}.0"] | |
} | |
} | |
}); | |
gpii.test.integration.resolveHandlerKey = function (that, payload) { | |
var pathKey = that.options.optionsPathKey; | |
if (typeof(pathKey) === "string") { | |
return fluid.get(payload.options, pathKey); | |
} else if (typeof(pathKey) === "function") { | |
return pathKey(payload.options); | |
} | |
}; | |
gpii.test.integration.mockSettingsHandler.setImpl = function (that, payload) { | |
var key = gpii.test.integration.resolveHandlerKey(that, payload); | |
var oldSettings = that.settingsStore[key]; | |
console.log("setSettings returning " + JSON.stringify(oldSettings)+ " for key ", key, " storing ", JSON.stringify(payload.settings)); | |
that.settingsStore[key] = payload.settings; | |
return oldSettings || null; | |
}; | |
gpii.test.integration.mockSettingsHandler.set = function (that, payload) { | |
return gpii.settingsHandlers.invokeSettingsHandler(that.setImpl, payload); | |
}; | |
gpii.test.integration.mockSettingsHandler.getImpl = function (that, payload) { | |
var key = gpii.test.integration.resolveHandlerKey(that, payload); | |
var oldSettings = that.settingsStore[key]; | |
console.log("getSettings returning " + JSON.stringify(oldSettings)+ " for key ", key); | |
return oldSettings || null; | |
}; | |
gpii.test.integration.mockSettingsHandler.get = function (that, payload) { | |
return gpii.settingsHandlers.invokeSettingsHandler(that.getImpl, payload); | |
}; | |
// The platform-specific registry of mock settings handlers | |
gpii.test.integration.registrySettingsHandlerKey = function (options) { | |
return options.hKey + "|" + options.path; | |
}; | |
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry", { | |
gradeNames: ["fluid.eventedComponent", "autoInit"], | |
rootPath: "gpii.test.integration.mockSettingsHandlers", // the global names for mocks will be deposited in here | |
members: { | |
settingsHandlers: {} | |
}, | |
invokers: { | |
resolveName: { | |
funcName: "gpii.test.integration.mockSettingsHandlerRegistry.resolveName", | |
args: ["{that}", "{arguments}.0"] | |
} | |
}, | |
listeners: { | |
onCreate: "gpii.test.integration.mockSettingsHandlerRegistry.populate" | |
} | |
}); | |
gpii.test.integration.mockSettingsHandlers = {}; | |
gpii.test.integration.mockSettingsHandlerRegistry.populate = function (that) { | |
fluid.each(that.options.settingsHandlers, function (options, key) { | |
var mock = gpii.test.integration.mockSettingsHandler(options); | |
that.settingsHandlers[key] = mock; | |
// Mount the mock handler at a global path | |
var setPath = that.options.rootPath + "." + key + ".set"; | |
fluid.setGlobalValue(setPath, mock.set); | |
fluid.setGlobalValue(that.options.rootPath + "." + key + ".get", mock.get); | |
}); | |
}; | |
gpii.test.integration.mockSettingsHandlerRegistry.resolveName = function (that, name) { | |
var mock = that.settingsHandlers[name]; | |
if (!mock) { | |
fluid.fail("Error in settings handler mock configuration - handler " + name + " is not registered"); | |
} else { | |
return that.options.rootPath + "." + name; | |
} | |
}; | |
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.universal", { | |
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry", "autoInit"], | |
settingsHandlers: { | |
"gpii.settingsHandlers.INISettingsHandler": { | |
optionsPathKey: "path" | |
}, | |
"gpii.settingsHandlers.XMLSettingsHandler": { | |
optionsPathKey: "path" | |
}, | |
"gpii.settingsHandlers.JSONSettingsHandler": { | |
optionsPathKey: "path" | |
}, | |
} | |
}); | |
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.windows", { | |
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry.universal", "autoInit"], | |
settingsHandlers: { | |
"gpii.windows.registrySettingsHandler": { | |
optionsPathKey: gpii.test.integration.registrySettingsHandlerKey | |
}, | |
"gpii.windows.spiSettingsHandler": { | |
async: true, | |
optionsPathKey: "setAction" | |
} | |
} | |
}); | |
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.linux", { | |
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry.universal", "autoInit"], | |
settingsHandlers: { | |
"gpii.gsettings": { | |
optionsPathKey: "schema" | |
}, | |
"gpii.orca": { | |
async: true, | |
optionsPathKey: "user" | |
}, | |
"gpii.alsa": { | |
optionsPathKey: "NONE" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment