2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2018-05-14 22:46:17 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2018, United States Government
|
2015-05-13 23:42:35 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2015-05-13 23:42:35 +00:00
|
|
|
* "License"); you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2015-05-13 23:42:35 +00:00
|
|
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
|
|
* this source code distribution or the Licensing information page available
|
|
|
|
* at runtime from the About dialog for additional information.
|
|
|
|
*****************************************************************************/
|
2014-11-06 16:03:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BundleLoaderSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
2014-11-06 22:28:22 +00:00
|
|
|
["../../src/load/BundleLoader"],
|
|
|
|
function (BundleLoader) {
|
2014-11-06 16:03:35 +00:00
|
|
|
|
2014-11-06 22:28:22 +00:00
|
|
|
describe("The bundle loader", function () {
|
|
|
|
var loader,
|
|
|
|
mockHttp,
|
|
|
|
mockLog,
|
2016-01-08 20:58:06 +00:00
|
|
|
mockRegistry,
|
2014-11-06 22:28:22 +00:00
|
|
|
testBundles;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2014-11-06 22:47:56 +00:00
|
|
|
testBundles = {
|
2016-05-19 18:29:13 +00:00
|
|
|
"bundles.json": ["bundle/a", "bundle/b"],
|
2014-11-06 22:47:56 +00:00
|
|
|
"bundle/a/bundle.json": {"someValue": 6},
|
|
|
|
"bundle/b/bundle.json": {"someValue": 7}
|
|
|
|
};
|
2014-11-06 22:28:22 +00:00
|
|
|
|
|
|
|
mockHttp = jasmine.createSpyObj("$http", ["get"]);
|
|
|
|
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]);
|
2016-01-08 20:58:06 +00:00
|
|
|
mockRegistry = jasmine.createSpyObj(
|
|
|
|
'legacyRegistry',
|
2016-05-19 18:29:13 +00:00
|
|
|
['list', 'contains', 'get']
|
2016-01-08 20:58:06 +00:00
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockRegistry.list.and.returnValue([]);
|
|
|
|
mockRegistry.contains.and.returnValue(false);
|
2016-01-08 20:58:06 +00:00
|
|
|
loader = new BundleLoader(mockHttp, mockLog, mockRegistry);
|
2014-11-06 22:28:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("accepts a JSON file name and loads all bundles", function () {
|
2014-11-06 22:47:56 +00:00
|
|
|
// Set up; return named bundles
|
2018-06-30 00:32:59 +00:00
|
|
|
mockHttp.get.and.returnValue(Promise.resolve({ data: [] }));
|
2014-11-06 22:28:22 +00:00
|
|
|
|
|
|
|
// Call load bundles
|
2018-06-30 00:32:59 +00:00
|
|
|
return loader.loadBundles("test-filename.json").then(function (bundles) {
|
2014-11-06 22:28:22 +00:00
|
|
|
// Should have loaded the file via $http
|
|
|
|
expect(mockHttp.get).toHaveBeenCalledWith("test-filename.json");
|
|
|
|
|
|
|
|
// Should have gotten an empty bundle list
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(bundles).toEqual([]);
|
2014-11-06 22:28:22 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-06 22:47:56 +00:00
|
|
|
it("accepts a list of bundle paths", function () {
|
|
|
|
// Set up; return named bundles
|
2018-06-30 00:32:59 +00:00
|
|
|
mockHttp.get.and.callFake(function (name) {
|
2014-11-06 22:47:56 +00:00
|
|
|
return Promise.resolve({data: testBundles[name]});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Call load bundles
|
2018-06-30 00:32:59 +00:00
|
|
|
return loader.loadBundles(["bundle/a", "bundle/b"]).then(function (bundles) {
|
2014-11-06 22:47:56 +00:00
|
|
|
// Should have gotten back two bundles
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(bundles.length).toEqual(2);
|
2014-11-06 22:47:56 +00:00
|
|
|
|
|
|
|
// They should have the values we expect; don't care about order,
|
|
|
|
// some map/reduce the summation.
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(bundles.map(function (call) {
|
2014-11-06 22:47:56 +00:00
|
|
|
return call.getDefinition().someValue;
|
|
|
|
}).reduce(function (a, b) {
|
|
|
|
return a + b;
|
|
|
|
}, 0)).toEqual(13);
|
2014-11-06 22:57:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("warns about, then ignores, missing bundle declarations", function () {
|
|
|
|
// File-not-found
|
2018-06-30 00:32:59 +00:00
|
|
|
mockHttp.get.and.returnValue(Promise.reject(new Error("test error")));
|
2014-11-06 22:57:32 +00:00
|
|
|
|
|
|
|
// Try and load
|
2018-06-30 00:32:59 +00:00
|
|
|
return loader.loadBundles(["some/bundle"]).then(function (bundles) {
|
|
|
|
// Should have gotten zero bundles
|
|
|
|
expect(bundles.length).toEqual(0);
|
2014-11-06 22:57:32 +00:00
|
|
|
|
|
|
|
// They should have the values we expect; don't care about order,
|
|
|
|
// some map/reduce the summation.
|
|
|
|
expect(mockLog.warn).toHaveBeenCalled();
|
2014-11-06 22:47:56 +00:00
|
|
|
});
|
|
|
|
});
|
2014-11-06 22:28:22 +00:00
|
|
|
|
2014-11-06 16:03:35 +00:00
|
|
|
|
2014-11-06 23:20:26 +00:00
|
|
|
it("warns about, then ignores, malformed bundle declarations", function () {
|
2014-11-06 22:57:32 +00:00
|
|
|
// File-not-found
|
2018-06-30 00:32:59 +00:00
|
|
|
mockHttp.get.and.returnValue(Promise.resolve(["I am not a valid bundle."]));
|
2014-11-06 22:57:32 +00:00
|
|
|
|
|
|
|
// Try and load
|
2018-06-30 00:32:59 +00:00
|
|
|
return loader.loadBundles(["some/bundle"]).then(function (bundles) {
|
2014-11-06 22:57:32 +00:00
|
|
|
// Should have gotten zero bundle
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(bundles.length).toEqual(0);
|
2014-11-06 22:57:32 +00:00
|
|
|
|
|
|
|
// They should have the values we expect; don't care about order,
|
|
|
|
// some map/reduce the summation.
|
|
|
|
expect(mockLog.warn).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-06 16:03:35 +00:00
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|