all files / sync/gpii/node_modules/orca/test/ orcaSettingsHandlerTests.js

93.1% Statements 27/29
100% Branches 0/0
83.33% Functions 10/12
93.1% Lines 27/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144                                                                                                                                                                                                                        20× 20×                  
/*
 * Orca Settings Handler Tests
 *
 * Copyright 2013, 2014 Emergya
 * Copyright 2015, 2016 RtF-US
 *
 * 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/linux/blob/master/LICENSE.txt
 *
 * 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.
 */
 
"use strict";
 
var fluid = require("universal"),
    jqUnit = fluid.require("node-jqunit");
 
require("orca");
var gpii = fluid.registerNamespace("gpii");
 
fluid.defaults("gpii.test.orca", {
    gradeNames: ["fluid.test.testEnvironment"],
    components: {
        tester: {
            type: "gpii.test.orca.tester"
        }
    }
});
 
fluid.defaults("gpii.test.orca.tester", {
    gradeNames: ["fluid.test.testCaseHolder"],
    payloads: null,
    originalSettings: null,
    components: {
        orcaSettingsHandler: {
            type: "gpii.orca.settingsHandler"
        }
    },
    events: {
        onGetReturnPayload: null,
        onSetReturnPayload: null
    },
    listeners: {
        onCreate: {
            funcName: "gpii.test.orca.tester.populate",
            args: ["{that}"]
        }
    },
    modules: [{
        name: "Orca Settings Handler Tests",
        tests: [{
           //expect: 13,
            name: "Get/Set tests",
            sequence: [{  // Check that we can retrieve settings
                func: "gpii.test.orca.get",
                args: ["{tester}", "{tester}.payloads.getPayload"]
            }, {
                listener: "gpii.test.orca.checkGetPayload",
                event: "{that}.events.onGetReturnPayload",
                args: ["{that}", "{arguments}.0"]
            }, {  // Check that set returns the expected payload
                func: "gpii.test.orca.set",
                args: ["{tester}", "{tester}.payloads.setPayload"]
            }, {
                listener: "gpii.test.orca.checkSetPayload",
                event: "{that}.events.onSetReturnPayload",
                args: ["{arguments}.0", "{tester}.payloads.setPayload"]
            }, {  // Check that settings are applied
                func: "gpii.test.orca.get",
                args: ["{tester}", "{tester}.payloads.getPayload"]
            }, {
                listener: "gpii.test.orca.checkActualSettings",
                event: "{that}.events.onGetReturnPayload",
                args: ["{arguments}.0", "{tester}.payloads.setPayload"]
            }, {  // Restore to the initial settings and check returned payload
                func: "gpii.test.orca.set",
                args: ["{tester}", "{tester}.originalSettings"]
            }, {
                listener: "gpii.test.orca.checkSetPayload",
                event: "{that}.events.onSetReturnPayload",
                args: ["{arguments}.0", "{tester}.originalSettings"]
            }, {  // Check that settings are back to its original values
                func: "gpii.test.orca.get",
                args: ["{tester}", "{tester}.payloads.getPayload"]
            }, {
                listener: "gpii.test.orca.checkActualSettings",
                event: "{that}.events.onGetReturnPayload",
                args: ["{arguments}.0", "{tester}.originalSettings"]
            }]
        }]
    }]
});
 
gpii.test.orca.tester.populate = function (that) {
    that.payloads = require(__dirname + "/payloads.json");
};
 
gpii.test.orca.get = function (that, payload) {
    var getPromise = that.orcaSettingsHandler.get(payload);
    getPromise.then(function (results) {
        that.events.onGetReturnPayload.fire(results);
    }, function (err) {
        fluid.fail(err);
    });
};
 
gpii.test.orca.set = function (that, payload) {
    var setPromise = that.orcaSettingsHandler.set(payload);
    setPromise.then(function (results) {
        that.events.onSetReturnPayload.fire(results);
    }, function (err) {
        fluid.fail(err);
    });
};
 
gpii.test.orca.checkGetPayload = function (that, results) {
    that.originalSettings = results;
    jqUnit.assertTrue("We can get settings from orca settings file",
                      (typeof(results) === "object"));
};
 
gpii.test.orca.checkSetPayload = function (results, payload) {
    fluid.each(results, function (solution, solutionId) {
        var settings = results[solutionId][0].settings;
        fluid.each(settings, function (v, k) {
            var expectedValue = payload[solutionId][0].settings[k];
            jqUnit.assertDeepEq("Setting " + k + " is being set well",
                                expectedValue, v.newValue);
        });
    });
};
 
gpii.test.orca.checkActualSettings = function (results, expected) {
    jqUnit.assertDeepEq("Orca config file contains the expected settings",
                        expected, results);
};
 
gpii.test.orca();