Merge remote-tracking branch 'github/master' into open1515

This commit is contained in:
Victor Woeltjen
2015-09-24 11:17:13 -07:00
168 changed files with 14612 additions and 6722 deletions

View File

@@ -25,8 +25,11 @@
* CompositionCapabilitySpec. Created by vwoeltje on 11/6/14.
*/
define(
["../../src/capabilities/CompositionCapability"],
function (CompositionCapability) {
[
"../../src/capabilities/CompositionCapability",
"../../src/capabilities/ContextualDomainObject"
],
function (CompositionCapability, ContextualDomainObject) {
"use strict";
var DOMAIN_OBJECT_METHODS = [
@@ -40,6 +43,7 @@ define(
describe("The composition capability", function () {
var mockDomainObject,
mockInjector,
mockContextualize,
mockObjectService,
composition;
@@ -47,7 +51,7 @@ define(
// so support that, but don't introduce complication of
// native promises.
function mockPromise(value) {
return {
return (value || {}).then ? value : {
then: function (callback) {
return mockPromise(callback(value));
}
@@ -70,11 +74,19 @@ define(
return (name === "objectService") && mockObjectService;
}
};
mockContextualize = jasmine.createSpy('contextualize');
// Provide a minimal (e.g. no error-checking) implementation
// of contextualize for simplicity
mockContextualize.andCallFake(function (domainObject, parentObject) {
return new ContextualDomainObject(domainObject, parentObject);
});
mockObjectService.getObjects.andReturn(mockPromise([]));
composition = new CompositionCapability(
mockInjector,
mockContextualize,
mockDomainObject
);
});
@@ -111,6 +123,98 @@ define(
});
it("allows domain objects to be added", function () {
var result,
testModel = { composition: [] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined);
mockChild.getId.andReturn('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
if (key === 'mutation') {
mutator(testModel);
return mockPromise(true);
}
});
composition.add(mockChild).then(function (domainObject) {
result = domainObject;
});
expect(testModel.composition).toEqual(['a']);
// Should have returned the added object in its new context
expect(result.getId()).toEqual('a');
expect(result.getCapability('context')).toBeDefined();
expect(result.getCapability('context').getParent())
.toEqual(mockDomainObject);
});
it("does not re-add IDs which are already present", function () {
var result,
testModel = { composition: [ 'a' ] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined);
mockChild.getId.andReturn('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
if (key === 'mutation') {
mutator(testModel);
return mockPromise(true);
}
});
composition.add(mockChild).then(function (domainObject) {
result = domainObject;
});
// Still just 'a'
expect(testModel.composition).toEqual(['a']);
// Should have returned the added object in its new context
expect(result.getId()).toEqual('a');
expect(result.getCapability('context')).toBeDefined();
expect(result.getCapability('context').getParent())
.toEqual(mockDomainObject);
});
it("can add objects at a specified index", function () {
var result,
testModel = { composition: [ 'a', 'b', 'c' ] },
mockChild = jasmine.createSpyObj("child", DOMAIN_OBJECT_METHODS);
mockDomainObject.getModel.andReturn(testModel);
mockObjectService.getObjects.andReturn(mockPromise({a: mockChild}));
mockChild.getCapability.andReturn(undefined);
mockChild.getId.andReturn('a');
mockDomainObject.useCapability.andCallFake(function (key, mutator) {
if (key === 'mutation') {
mutator(testModel);
return mockPromise(true);
}
});
composition.add(mockChild, 1).then(function (domainObject) {
result = domainObject;
});
// Still just 'a'
expect(testModel.composition).toEqual(['b', 'a', 'c']);
// Should have returned the added object in its new context
expect(result.getId()).toEqual('a');
expect(result.getCapability('context')).toBeDefined();
expect(result.getCapability('context').getParent())
.toEqual(mockDomainObject);
});
});
}
);
);

View File

@@ -32,7 +32,9 @@ define(
describe("The persisted model provider", function () {
var mockQ,
mockPersistenceService,
SPACE = "some space",
SPACE = "space0",
spaces = [ "space1" ],
modTimes,
provider;
function mockPromise(value) {
@@ -51,12 +53,14 @@ define(
}
beforeEach(function () {
modTimes = {};
mockQ = { when: mockPromise, all: mockAll };
mockPersistenceService = {
readObject: function (space, id) {
return mockPromise({
space: space,
id: id
id: id,
modified: (modTimes[space] || {})[id]
});
}
};
@@ -64,7 +68,8 @@ define(
provider = new PersistedModelProvider(
mockPersistenceService,
mockQ,
SPACE
SPACE,
spaces
);
});
@@ -82,6 +87,24 @@ define(
});
});
it("reads object models from multiple spaces", function () {
var models;
modTimes.space1 = {
'x': 12321
};
provider.getModels(["a", "x", "zz"]).then(function (m) {
models = m;
});
expect(models).toEqual({
a: { space: SPACE, id: "a" },
x: { space: 'space1', id: "x", modified: 12321 },
zz: { space: SPACE, id: "zz" }
});
});
});
}
);
);

View File

@@ -0,0 +1,90 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "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.
*
* Open MCT Web includes source code licensed under additional open source
* 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.
*****************************************************************************/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/services/Contextualize"],
function (Contextualize) {
"use strict";
var DOMAIN_OBJECT_METHODS = [
'getId',
'getModel',
'getCapability',
'hasCapability',
'useCapability'
];
describe("The 'contextualize' service", function () {
var mockLog,
mockDomainObject,
mockParentObject,
testParentModel,
contextualize;
beforeEach(function () {
testParentModel = { composition: ["abc"] };
mockLog = jasmine.createSpyObj(
"$log",
[ "error", "warn", "info", "debug" ]
);
mockDomainObject =
jasmine.createSpyObj('domainObject', DOMAIN_OBJECT_METHODS);
mockParentObject =
jasmine.createSpyObj('parentObject', DOMAIN_OBJECT_METHODS);
mockDomainObject.getId.andReturn("abc");
mockDomainObject.getModel.andReturn({});
mockParentObject.getId.andReturn("parent");
mockParentObject.getModel.andReturn(testParentModel);
contextualize = new Contextualize(mockLog);
});
it("attaches a context capability", function () {
var contextualizedObject =
contextualize(mockDomainObject, mockParentObject);
expect(contextualizedObject.getId()).toEqual("abc");
expect(contextualizedObject.getCapability("context"))
.toBeDefined();
expect(contextualizedObject.getCapability("context").getParent())
.toBe(mockParentObject);
});
it("issues a warning if composition does not match", function () {
// Precondition - normally it should not issue a warning
contextualize(mockDomainObject, mockParentObject);
expect(mockLog.warn).not.toHaveBeenCalled();
testParentModel.composition = ["xyz"];
contextualize(mockDomainObject, mockParentObject);
expect(mockLog.warn).toHaveBeenCalled();
});
});
}
);

View File

@@ -24,6 +24,7 @@
"objects/DomainObject",
"objects/DomainObjectProvider",
"services/Contextualize",
"services/Now",
"services/Throttle",
"services/Topic",