Пример #1
0
gpii.test.cloudBased.oauth2.buildDisruptedFixture = function (testDef, commonRec, disruption, baseDir) {
    var options = fluid.defaults(disruption.gradeName);
    testDef = gpii.test.cloudBased.oauth2.buildTestFixtureCommon(testDef, commonRec, baseDir);
    if (options.expect) {
        testDef.expect = options.expect;
    }
    if (disruption.expected) {
        testDef.expected = disruption.expected;
    }
    if (disruption.name) {
        testDef.name += " - " + disruption.name;
    }
    testDef.gradeNames = testDef.gradeNames.concat(fluid.makeArray(options.testCaseGradeNames));
    var sequence = gpii.test.elementsBetween(fluid.getGlobalValue(options.sequenceName),
        options.startAt, options.truncateAt);
    if (options.finalRecord) {
        sequence.push(options.finalRecord);
    }
    if (options.insertRecords) { // TODO: replace all this special-case manipulation with FLUID-3504 when it is implemented
        gpii.test.insertIntoArray(sequence, options.insertAt, options.insertRecords);
    }
    testDef.sequence = sequence;
    testDef.expectedStatusCode = disruption.expectedStatusCode || options.expectedStatusCode;
    console.log("Issuing sequence" + JSON.stringify(sequence, null, 2));
    var changes = fluid.makeArray(options.changes).concat(fluid.makeArray(disruption.changes));
    fluid.set(testDef, [options.recordName, "changes"], changes);
    return testDef;
};
gpii.test.cloudBased.oauth2.buildTestFixtureCommon = function (testDef, commonRec, baseDir) {
    testDef = fluid.extend(true, {}, testDef, commonRec);

    testDef.sequence = fluid.makeArray(testDef.sequence);
    testDef.gradeNames = fluid.makeArray(testDef.gradeNames);
    testDef.gradeNames.push("gpii.test.cloudBased.oauth2.testCaseHolder");
    testDef.config = gpii.test.cloudBased.gpiiConfig(baseDir);
    return testDef;
};
Пример #3
0
 fluid.each(secondary.contexts, function (context, contextId) {
     var mcontext = master.contexts[contextId];
     // if not in master, just copy over from secondary:
     if (!mcontext) {
         master.contexts[contextId] = context;
     } else {
         // preferences and metadata should be the only things varying
         fluid.extend(true, mcontext.preferences, context.preferences);
         mcontext.metadata = fluid.makeArray(mcontext.metadata).concat(fluid.makeArray(context.metadata));
     }
 });
Пример #4
0
kettle.config.createDefaultsImpl = function (prefix, filePath) {
    var fullPath;
    if (filePath.charAt(0) === "%") {
        fullPath = fluid.module.resolvePath(filePath);
        prefix = path.dirname(fullPath);
    } else {
        var fileName = path.basename(filePath),
            dirName = path.dirname(filePath);
        prefix = path.resolve(prefix, dirName);
        fullPath = path.resolve(prefix, fileName);
    }
    var configFile;
    var testFiles = [fullPath, fullPath + ".json", fullPath + ".json5"];
    var firstExisting = kettle.firstExistingFile(testFiles);
    if (!firstExisting) {
        fluid.fail("Could not find a config file at any of the paths ", testFiles.join(", "));
    }
    var parser = kettle.JSON.readFileSync(firstExisting, "reading config file at " + firstExisting);
    parser.then(function (parsed) {
        configFile = parsed;
    }, function (rejection) {
        fluid.fail(rejection.message);
    });

    kettle.config.checkConfig(configFile);
    var gradeNames = ["kettle.config"];

    kettle.config.loadSubConfigs(prefix, firstExisting, configFile.mergeConfigs, gradeNames);
    kettle.config.loadSubConfigs(prefix, firstExisting, configFile.loadConfigs);

    var requires = fluid.makeArray(configFile.require);
    fluid.each(requires, function loadRequire(requireId) {
        if (requireId.charAt(0) === "%") {
            requireId = fluid.module.resolvePath(requireId);
        }
        try {
            var resolved = resolve.sync(requireId, {
                basedir: prefix
            });
            require(resolved);
        } catch (e) {
            e.message += " while trying to resolve require directive for " + requireId + " in config at path " + firstExisting;
            throw (e);
        }
    });
    configFile.type = configFile.type || "kettle.config." + fluid.allocateGuid();
    configFile.options = configFile.options || {};
    configFile.options.gradeNames = gradeNames.concat(fluid.makeArray(
        configFile.options.gradeNames));
    fluid.defaults(configFile.type, configFile.options);
    fluid.log(fluid.logLevel.TRACE, "Created defaults for config type " + configFile.type + ": " + fluid.prettyPrintJSON(configFile.options));
    return configFile.type;
};
Пример #5
0
 fluid.each(requestOptions.formData.files, function (filePath, fieldKey) {
     var filePaths = fluid.makeArray(filePath);
     filePaths.forEach(function (filePath) {
         var resolved = fluid.module.resolvePath(filePath);
         form.append(fieldKey, fs.createReadStream(resolved));
     });
 });
Пример #6
0
gpii.acceptanceTesting.buildFlowManagerTestFixture = function (testDef) {
    testDef.expect = 1;
    testDef.sequence = fluid.makeArray(testDef.sequence);

    testDef.members = {
        settingsStore: {}
    };

    testDef.components = $.extend(true, testDef.components, {
        fmrequest: {
            type: "kettle.tests.request.http",
            options: {
                requestOptions: {
                    path: "/%token/settings/%appinfo",
                    port: 8081,
                    passthrough: testDef.expected
                },
                termMap: {
                    token: "{tests}.options.token",
                    appinfo: "{tests}.options.appinfo"
                }
            }
        }
    });

    testDef.sequence.unshift({
        func: "{fmrequest}.send"
    }, {
        event: "{fmrequest}.events.onComplete",
        listenerMaker: "gpii.acceptanceTesting.FMRequestListenerMaker",
        makerArgs: ["{tests}.options.expected"]
    });

    return testDef;
};
Пример #7
0
 fluid.log = function (logLevel) {
     var togo = kettle.tests.originalFluidLog.apply(null, arguments); 
     if (!notifying && logLevel.priority <= fluid.logLevel.FAIL.priority) {
         notifying = true;          
         fluid.staticEnvironment.logNotifierHolder.events.logNotifier.fire(fluid.makeArray(arguments));
         notifying = false;
     }
     return togo;
 };
gpii.test.cloudBased.oauth2.bootstrapDisruptedTest = function (testDefs, commonRec,
    disruptions, baseDir) {
    testDefs = fluid.makeArray(testDefs);
    return fluid.transform(disruptions, function (disruption) {
        return kettle.test.bootstrapServer(testDefs, function (testDef) {
            return gpii.test.cloudBased.oauth2.buildDisruptedFixture(testDef, commonRec, disruption, baseDir);
        });
    });
};
Пример #9
0
        return function () {
            var expect = testData.expect[expectedIndex++].slice();
            var expectedName = expect.shift();

            jqUnit.assertEquals("The expected handler should be called.", expectedName, name);

            var args = fluid.makeArray(arguments);
            jqUnit.assertDeepEq("The handler should be called with expected parameters.", expect, args);

        };
Пример #10
0
colors.stylize = function (str, styles) {
    styles = fluid.makeArray(styles);
  
    var togo = str;
    for (var i = 0; i < styles.length; ++i) {
        togo = "\u001b[" + colors.styles[styles[i]][0] + "m" + togo +
            "\u001b[" + colors.styles[styles[i]][1] + "m";
    }
    return togo;
};
gpii.test.elementsBetween = function (origArray, start, end) {
    var array = fluid.makeArray(origArray);
    start = start || 0;
    if (!end && end !== 0) {
        end = array.length;
    }
    array.length = end;
    array.splice(0, start);
    return array;
};
Пример #12
0
gpii.test.cloudBased.oauth2.buildDisruptedFixture = function (testDef, commonRec, disruption, config, testCaseGrade) {
    var options = fluid.defaults(disruption.sequenceGrade);
    testDef = gpii.test.cloudBased.oauth2.buildTestFixtureCommon(testDef, commonRec, config, testCaseGrade);
    if (options.expect) {
        testDef.expect = options.expect;
    }
    if (disruption.expected) {
        testDef.expected = disruption.expected;
    }
    if (disruption.name) {
        testDef.name += " - " + disruption.name;
    }
    testDef.gradeNames = testDef.gradeNames.concat(fluid.makeArray(options.testCaseGradeNames));

    testDef.expectedStatusCode = disruption.expectedStatusCode || options.expectedStatusCode;

    var changes = fluid.makeArray(options.changes).concat(fluid.makeArray(disruption.changes));
    fluid.set(testDef, [options.recordName, "changes"], changes);
    return testDef;
};
Пример #13
0
 fluid.each(that.options.databases, function (dbConfig, key) {
     var db = new MyPouchDB(key);
     that.databaseInstances[key] = db;
     if (dbConfig.data) {
         var dataSetPaths = fluid.makeArray(dbConfig.data);
         fluid.each(dataSetPaths, function (dataSetPath) {
             var data = fluid.require(dataSetPath);
             promises.push(db.bulkDocs(data));
         });
     }
 });
Пример #14
0
    gpii.ontologyHandler.mergePrefsSets = function (master, secondary) {
        master = fluid.copy(master);
        secondary = fluid.copy(secondary);

        fluid.each(secondary.contexts, function (context, contextId) {
            var mcontext = master.contexts[contextId];
            // if not in master, just copy over from secondary:
            if (!mcontext) {
                master.contexts[contextId] = context;
            } else {
                // preferences and metadata should be the only things varying
                fluid.extend(true, mcontext.preferences, context.preferences);
                mcontext.metadata = fluid.makeArray(mcontext.metadata).concat(fluid.makeArray(context.metadata));
            }
        });

        // merge outer metadata block
        master.metadata = fluid.makeArray(master.metadata).concat(fluid.makeArray(secondary.metadata));
        return master;
    };
Пример #15
0
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();
    testDef = gpii.test.pouch.addPouchFixturesToTestDef(testDef);

    return testDef;
};
gpii.test.cloudBased.oauth2.buildDisruptedFixture = function (testDef, commonRec, disruption, baseDir) {
    var options = fluid.defaults(disruption.gradeName);
    testDef = gpii.test.cloudBased.oauth2.buildTestFixtureCommon(testDef, commonRec, baseDir);
    if (options.expect) {
        testDef.expect = options.expect;
    }
    if (disruption.expected) {
        testDef.expected = disruption.expected;
    }
    if (disruption.name) {
        testDef.name += " - " + disruption.name;
    }
    testDef.gradeNames = testDef.gradeNames.concat(fluid.makeArray(options.testCaseGradeNames));
    testDef.sequence = gpii.test.elementsBetween(fluid.getGlobalValue(options.sequenceName));

    testDef.expectedStatusCode = disruption.expectedStatusCode || options.expectedStatusCode;
    testDef = gpii.test.pouch.addPouchFixturesToTestDef(testDef);

    fluid.log("oauth2.buildDisruptedFixture issuing sequence" + JSON.stringify(testDef.sequence, null, 2));
    var changes = fluid.makeArray(options.changes).concat(fluid.makeArray(disruption.changes));
    fluid.set(testDef, [options.recordName, "changes"], changes);

    return testDef;
};
Пример #17
0
kettle.config.loadSubConfigs = function (prefix, fullPath, configPaths, gradeNames) {
    configPaths = fluid.makeArray(configPaths);
    fluid.each(configPaths, function loadConfigFromPath(configPath) {
        var loadedDefaults;
        try {
            loadedDefaults = kettle.config.createDefaultsImpl(prefix, configPath);
        } catch (e) {
            e.message += " while loading included configs for config at path " + fullPath;
            throw(e);
        }
        if (gradeNames) {
            gradeNames.push(loadedDefaults);
        }
    });
};
Пример #18
0
gpii.webdriver.navigateHelper = function (that, args) {
    var argsArray = fluid.makeArray(args);
    var navFnName = argsArray[0];
    var navFnArgs = argsArray.slice(1);
    var navigate = that.driver.navigate();

    if (navigate[navFnName]) {
        var promise = navigate[navFnName].apply(navigate, navFnArgs);
        promise.then(that.events.onNavigateHelperComplete.fire)["catch"](that.events.onError.fire);
        return promise;
    }
    else {
        var failurePromise = new webdriver.promise.Promise();
        failurePromise["catch"](that.events.onError.fire);
        failurePromise.cancel("Navigation function `" + navFnName + "` does not exist...");
        return failurePromise;
    }
};
Пример #19
0
            that[method] = function () {
                var deferred = when.defer(),
                    promise = deferred.promise, promiseImpl = {},
                    args = fluid.makeArray(arguments);

                // We can not directly modify when's then method. It is set to
                // be non-writable (Throws TypeError if we try to assignment operator).
                promiseImpl.then = function (callback) {
                    callback = that.callbackWrapper.wrap(callback);
                    promise.then.apply(null, [callback]);
                };

                args.push(that.callbackWrapper.wrap(function () {
                    deferred.resolve.apply(null, fluid.makeArray(arguments));
                }));
                that.rawSource[method].apply(null, args);

                return promiseImpl;
            };
Пример #20
0
kettle.middleware.CORSHandle = function (request, allowMethods, origin, credentials) {
    var res = request.res,
        req = request.req,
        reqOrigin = req.headers.origin;
    // Handle a preflight OPTIONS request as well.
    allowMethods = fluid.makeArray(allowMethods).concat(["OPTIONS", "PUT", "POST"]);

    // Add CORS response headers.
    res.header("Access-Control-Allow-Origin",
        origin === "*" || origin.indexOf(reqOrigin) > -1 ? reqOrigin : "null");
    res.header("Access-Control-Allow-Credentials", credentials);
    res.header("Access-Control-Allow-Methods", allowMethods.join(","));
    res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");

    if (req.method === "OPTIONS") {
        res.sendStatus(204);
    }
    return fluid.promise().resolve();
};
Пример #21
0
            that[method] = function wrappedMethod() {
                var deferred = when.defer(),
                    promise = deferred.promise, promiseImpl = {},
                    args = fluid.makeArray(arguments),
                    wrap = that.callbackWrapper.wrap;

                // We can not directly modify when's then method. It is set to
                // be non-writable (Throws TypeError if we try to assignment
                // operator).
                promiseImpl.then = function then(callback) {
                    promise.then.apply(null, [wrap(callback)]);
                };

                args.push(wrap(function wrappedCallback() {
                    deferred.resolve.apply(null, fluid.makeArray(arguments));
                }));
                originalMethod.apply(null, args);

                return promiseImpl;
            };
Пример #22
0
 var createDefaultsImpl = function (prefix, filePath) {
     var fileName = path.basename(filePath),
         filePathPrefix = filePath.slice(0, filePath.indexOf(fileName));
     prefix = path.resolve(prefix, filePathPrefix);
     var fullPath = path.resolve(prefix, fileName),
         configFile = JSON.parse(fs.readFileSync(fullPath)),
         includes = configFile.includes,
         gradeNames = [];
     kettle.config.loadModules(configFile.modules, prefix);
     fluid.each(includes, function loadConfigFromPath(importPath) {
         gradeNames.push(createDefaultsImpl(prefix, importPath));
     });
     configFile.typeName = configFile.typeName ||
         fluid.model.composeSegments("kettle.config", fluid.allocateGuid());
     configFile.options = configFile.options || {};
     configFile.options.gradeNames = fluid.makeArray(
         configFile.options.gradeNames).concat(gradeNames);
     fluid.defaults(configFile.typeName, configFile.options);
     return configFile.typeName;
 };
Пример #23
0
kettle.server.evaluateRoute = function (server, req, originOptions) {
    var router = kettle.server.getRouter(server, req);
    var match = router.match(req);
    if (match) {
        var handler = match.handler;
        if (!handler.type) {
            fluid.fail("Error in Kettle application definition - handler ", fluid.censorKeys(handler, ["app"]), " must have a request grade name registered as member \"type\"");
        }
        fluid.log("Invoking handler " + handler.type + " for route " + handler.route + " with expectedGrade " + originOptions.expectedRequestGrade);
        var defaults = fluid.getMergedDefaults(handler.type, handler.gradeNames);
        if (!fluid.hasGrade(defaults, "kettle.request")) {
            fluid.fail("Error in Kettle application definition - couldn't load handler " + handler.type + " and gradeNames " +
                JSON.stringify(fluid.makeArray(handler.gradeNames)) + " to a component derived from kettle.request - got defaults of " + JSON.stringify(defaults));
        }
        match.output.mismatchError = kettle.server.checkCompatibleRequest(originOptions.expectedRequestGrade, defaults.gradeNames);
        if (match.output.mismatchError) { // In the case of a request type mismatch, create a special "mismatch" request handling component
            handler.type = originOptions.expectedRequestGrade + ".mismatch";
            handler.gradeNames = [];
        }
    }
    return match;
};
 gpii.config.mergeDemands = function (target, source) {
     target = fluid.makeArray(target);
     source = fluid.makeArray(source);
     return target.concat(source);
 };
Пример #25
0
jqUnit.log = function () {
    var args = fluid.makeArray(arguments);
    args.unshift("jq: ");
    console.log.apply(null, args);
};
Пример #26
0
gpii.acceptanceTesting.buildSingleTestFixture = function (testDef) {
    var processes = testDef.processes;

    testDef.expect = 4 + processes.length * 2;
    testDef.sequence = fluid.makeArray(testDef.sequence);

    testDef.members = {
        settingsStore: {}
    };

    testDef.components = $.extend(true, testDef.components, {
        logout: {
            type: "kettle.tests.request.http",
            options: {
                requestOptions: {
                    path: "/user/%token/logout",
                    port: 8081
                },
                termMap: {
                    token: "{tests}.options.token"
                }
            }
        },
        login: {
            type: "kettle.tests.request.http",
            options: {
                requestOptions: {
                    path: "/user/%token/login",
                    port: 8081
                },
                termMap: {
                    token: "{tests}.options.token"
                }
            }
        },
        exec: {
            type: "gpii.acceptanceTesting.exec"
        }
    });

    testDef.sequence.unshift({
        func: "gpii.acceptanceTesting.snapshotSettings",
        args: ["{tests}.options.settingsHandlers", "{tests}.settingsStore"]
    }, {
        func: "{login}.send"
    }, {
        event: "{login}.events.onComplete",
        listener: "gpii.acceptanceTesting.loginRequestListen"
    }, {
        func: "gpii.acceptanceTesting.checkConfiguration",
        args: "{tests}.options.settingsHandlers"
    });

    // For each process, run the command, then check that we get the
    // expected output
    fluid.each(processes, function (process, pindex) {
        testDef.sequence.push({
            func: "{exec}.exec",
            args: [
                fluid.model.composeSegments("{tests}.options.processes",
                    pindex),
                fluid.model.composeSegments("{tests}.options.processes", pindex,
                    "expectConfigured")
            ]
        }, {
            event: "{exec}.events.onExecExit",
            listener: "gpii.acceptanceTesting.onExecExit"
        });
    });

    testDef.sequence.push({
        func: "{logout}.send"
    }, {
        event: "{logout}.events.onComplete",
        listener: "gpii.acceptanceTesting.logoutRequestListen"
    });

    // Check that the processes are in the expected state after logout
    fluid.each(processes, function (process, pindex) {
        testDef.sequence.push({
            func: "{exec}.exec",
            args: [
                fluid.model.composeSegments("{tests}.options.processes",
                    pindex),
                fluid.model.composeSegments("{tests}.options.processes", pindex,
                    "expectRestored")
            ]
        }, {
            event: "{exec}.events.onExecExit",
            listener: "gpii.acceptanceTesting.onExecExit"
        });
    });

    testDef.sequence.push({
        func: "gpii.acceptanceTesting.checkRestoredConfiguration",
        args: ["{tests}.options.settingsHandlers", "{tests}.settingsStore"]
    });

    return testDef;
};
Пример #27
0
 args.push(that.callbackWrapper.wrap(function () {
     deferred.resolve.apply(null, fluid.makeArray(arguments));
 }));
Пример #28
0
fluid.each(gpii.userListeners.pcsc.knownCards, function (card) {
    card.atrs = [];
    fluid.each(fluid.makeArray(card.atr), function (atr) {
        card.atrs.push(Buffer.from(atr.replace(/\s+/g, ""), "hex"));
    });
});
Пример #29
0
kettle.tests.notifyGlobalError = function () {
    fluid.staticEnvironment.logNotifierHolder.events.logNotifier.fire(fluid.makeArray(arguments));
};
Пример #30
0
 that[method] = function () {
     var args = fluid.makeArray(arguments),
         callback = args[args.length - 1];
     args[args.length - 1] = that.callbackWrapper.wrap(callback);
     that.rawSource[method].apply(null, args);
 };