2015-06-11 21:22:18 +00:00
|
|
|
/*****************************************************************************
|
2018-05-14 22:46:17 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2018, United States Government
|
2015-06-11 21:22:18 +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-06-11 21:22:18 +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-06-11 21:22:18 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
[
|
|
|
|
'../../src/services/CopyService',
|
|
|
|
'../DomainObjectFactory'
|
|
|
|
],
|
|
|
|
function (CopyService, domainObjectFactory) {
|
|
|
|
|
|
|
|
function synchronousPromise(value) {
|
2015-11-03 02:31:14 +00:00
|
|
|
if (value && value.then) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
var promise = {
|
|
|
|
then: function (callback) {
|
|
|
|
return synchronousPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
2018-06-30 00:32:59 +00:00
|
|
|
spyOn(promise, 'then').and.callThrough();
|
2015-06-11 18:58:53 +00:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("CopyService", function () {
|
2015-09-22 22:42:39 +00:00
|
|
|
var policyService;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
policyService = jasmine.createSpyObj(
|
|
|
|
'policyService',
|
|
|
|
['allow']
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
describe("validate", function () {
|
|
|
|
|
2015-09-22 22:42:39 +00:00
|
|
|
var copyService,
|
2015-06-11 18:58:53 +00:00
|
|
|
object,
|
|
|
|
parentCandidate,
|
|
|
|
validate;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
copyService = new CopyService(
|
|
|
|
null,
|
|
|
|
policyService
|
|
|
|
);
|
|
|
|
object = domainObjectFactory({
|
2015-06-12 16:39:24 +00:00
|
|
|
name: 'object',
|
|
|
|
capabilities: {
|
|
|
|
type: { type: 'object' }
|
|
|
|
}
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
|
|
|
parentCandidate = domainObjectFactory({
|
2015-06-12 16:39:24 +00:00
|
|
|
name: 'parentCandidate',
|
|
|
|
capabilities: {
|
|
|
|
type: { type: 'parentCandidate' }
|
|
|
|
}
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
|
|
|
validate = function () {
|
|
|
|
return copyService.validate(object, parentCandidate);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not allow invalid parentCandidate", function () {
|
|
|
|
parentCandidate = undefined;
|
|
|
|
expect(validate()).toBe(false);
|
|
|
|
parentCandidate = {};
|
|
|
|
expect(validate()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not allow copying into source object", function () {
|
|
|
|
object.id = parentCandidate.id = 'abc';
|
|
|
|
expect(validate()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("defers to policyService", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
object.id = 'a';
|
|
|
|
parentCandidate.id = 'b';
|
|
|
|
});
|
|
|
|
|
2015-06-12 16:39:24 +00:00
|
|
|
it("calls policy service with correct args", function () {
|
|
|
|
validate();
|
|
|
|
expect(policyService.allow).toHaveBeenCalledWith(
|
|
|
|
"composition",
|
2017-03-27 00:02:00 +00:00
|
|
|
parentCandidate,
|
2017-02-21 23:14:35 +00:00
|
|
|
object
|
2015-06-12 16:39:24 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
it("and returns false", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
policyService.allow.and.returnValue(false);
|
2015-06-11 18:58:53 +00:00
|
|
|
expect(validate()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("and returns true", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
policyService.allow.and.returnValue(true);
|
2015-06-11 18:58:53 +00:00
|
|
|
expect(validate()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("perform", function () {
|
|
|
|
|
|
|
|
var mockQ,
|
2015-11-04 23:38:22 +00:00
|
|
|
mockDeferred,
|
2015-06-11 18:58:53 +00:00
|
|
|
copyService,
|
|
|
|
object,
|
|
|
|
newParent,
|
|
|
|
copyResult,
|
2015-11-02 16:44:08 +00:00
|
|
|
copyFinished,
|
2015-11-03 06:50:47 +00:00
|
|
|
persistObjectPromise,
|
2015-12-03 20:49:54 +00:00
|
|
|
persistenceCapability,
|
|
|
|
instantiationCapability,
|
|
|
|
compositionCapability,
|
|
|
|
locationCapability,
|
2015-11-05 04:48:22 +00:00
|
|
|
resolvedValue;
|
2015-06-11 18:58:53 +00:00
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
beforeEach(function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
policyService.allow.and.returnValue(true);
|
2015-12-03 20:49:54 +00:00
|
|
|
|
2015-11-02 16:44:08 +00:00
|
|
|
persistObjectPromise = synchronousPromise(undefined);
|
2015-12-03 20:49:54 +00:00
|
|
|
|
|
|
|
instantiationCapability = jasmine.createSpyObj(
|
|
|
|
"instantiation",
|
2016-05-19 18:29:13 +00:00
|
|
|
["invoke"]
|
2015-12-03 20:49:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
persistenceCapability = jasmine.createSpyObj(
|
|
|
|
"persistenceCapability",
|
2016-05-19 18:29:13 +00:00
|
|
|
["persist", "getSpace"]
|
2015-11-03 06:50:47 +00:00
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
persistenceCapability.persist.and.returnValue(persistObjectPromise);
|
2015-11-03 06:50:47 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
compositionCapability = jasmine.createSpyObj(
|
|
|
|
'compositionCapability',
|
|
|
|
['invoke', 'add']
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
compositionCapability.add.and.callFake(synchronousPromise);
|
2015-11-04 01:39:05 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
locationCapability = jasmine.createSpyObj(
|
|
|
|
'locationCapability',
|
|
|
|
['isLink']
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
locationCapability.isLink.and.returnValue(false);
|
2015-11-04 23:38:22 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
mockDeferred = jasmine.createSpyObj(
|
|
|
|
'mockDeferred',
|
|
|
|
['notify', 'resolve', 'reject']
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockDeferred.notify.and.callFake(function () {});
|
|
|
|
mockDeferred.resolve.and.callFake(function (value) {
|
2016-05-19 18:29:13 +00:00
|
|
|
resolvedValue = value;
|
|
|
|
});
|
2015-11-04 23:38:22 +00:00
|
|
|
mockDeferred.promise = {
|
2016-05-19 18:29:13 +00:00
|
|
|
then: function (callback) {
|
2015-11-04 23:38:22 +00:00
|
|
|
return synchronousPromise(callback(resolvedValue));
|
|
|
|
}
|
2015-11-05 04:48:22 +00:00
|
|
|
};
|
2015-11-04 23:38:22 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
mockQ = jasmine.createSpyObj(
|
|
|
|
'mockQ',
|
|
|
|
['when', 'all', 'reject', 'defer']
|
|
|
|
);
|
2018-06-30 00:32:59 +00:00
|
|
|
mockQ.reject.and.returnValue(synchronousPromise(undefined));
|
|
|
|
mockQ.when.and.callFake(synchronousPromise);
|
|
|
|
mockQ.all.and.callFake(function (promises) {
|
2015-11-04 23:38:22 +00:00
|
|
|
var result = {};
|
|
|
|
Object.keys(promises).forEach(function (k) {
|
2016-05-19 18:29:13 +00:00
|
|
|
promises[k].then(function (v) {
|
|
|
|
result[k] = v;
|
|
|
|
});
|
2015-11-04 23:38:22 +00:00
|
|
|
});
|
|
|
|
return synchronousPromise(result);
|
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
mockQ.defer.and.returnValue(mockDeferred);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
});
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
describe("on domain object without composition", function () {
|
|
|
|
beforeEach(function () {
|
2015-12-03 20:49:54 +00:00
|
|
|
var objectCopy;
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
newParent = domainObjectFactory({
|
|
|
|
name: 'newParent',
|
|
|
|
id: '456',
|
|
|
|
model: {
|
|
|
|
composition: []
|
2015-11-03 06:50:47 +00:00
|
|
|
},
|
|
|
|
capabilities: {
|
2015-12-03 20:49:54 +00:00
|
|
|
instantiation: instantiationCapability,
|
|
|
|
persistence: persistenceCapability,
|
|
|
|
composition: compositionCapability
|
2015-06-11 18:58:53 +00:00
|
|
|
}
|
|
|
|
});
|
2015-11-04 23:38:22 +00:00
|
|
|
|
|
|
|
object = domainObjectFactory({
|
|
|
|
name: 'object',
|
|
|
|
id: 'abc',
|
|
|
|
model: {
|
|
|
|
name: 'some object',
|
2015-12-03 20:49:54 +00:00
|
|
|
location: '456',
|
|
|
|
someOtherAttribute: 'some other value',
|
|
|
|
embeddedObjectAttribute: {
|
|
|
|
name: 'Some embedded object'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
capabilities: {
|
|
|
|
persistence: persistenceCapability
|
2015-11-04 23:38:22 +00:00
|
|
|
}
|
2015-11-03 02:31:14 +00:00
|
|
|
});
|
2015-12-03 20:49:54 +00:00
|
|
|
|
|
|
|
objectCopy = domainObjectFactory({
|
|
|
|
name: 'object',
|
|
|
|
id: 'abc.copy.fdgdfgdf',
|
|
|
|
capabilities: {
|
|
|
|
persistence: persistenceCapability,
|
|
|
|
location: locationCapability
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
instantiationCapability.invoke.and.callFake(
|
2016-05-19 18:29:13 +00:00
|
|
|
function (model) {
|
2015-12-03 20:49:54 +00:00
|
|
|
objectCopy.model = model;
|
|
|
|
return objectCopy;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
copyService = new CopyService(mockQ, policyService);
|
2015-06-11 18:58:53 +00:00
|
|
|
copyResult = copyService.perform(object, newParent);
|
|
|
|
copyFinished = jasmine.createSpy('copyFinished');
|
|
|
|
copyResult.then(copyFinished);
|
|
|
|
});
|
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
it("uses persistence capability", function () {
|
|
|
|
expect(persistenceCapability.persist)
|
|
|
|
.toHaveBeenCalled();
|
|
|
|
});
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
it("deep clones object model", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
var newModel = copyFinished.calls.all()[0].args[0].getModel();
|
2015-06-11 18:58:53 +00:00
|
|
|
expect(newModel).toEqual(object.model);
|
|
|
|
expect(newModel).not.toBe(object.model);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a promise", function () {
|
|
|
|
expect(copyResult).toBeDefined();
|
|
|
|
expect(copyFinished).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("on domainObject with composition", function () {
|
2016-03-04 20:56:14 +00:00
|
|
|
var childObject,
|
2015-12-03 20:49:54 +00:00
|
|
|
objectClone,
|
2018-08-07 21:47:50 +00:00
|
|
|
childObjectClone;
|
2015-06-11 18:58:53 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2015-12-03 20:49:54 +00:00
|
|
|
var invocationCount = 0,
|
|
|
|
objectClones;
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
instantiationCapability.invoke.and.callFake(
|
2016-05-19 18:29:13 +00:00
|
|
|
function (model) {
|
2015-12-03 20:49:54 +00:00
|
|
|
var cloneToReturn = objectClones[invocationCount++];
|
|
|
|
cloneToReturn.model = model;
|
|
|
|
return cloneToReturn;
|
|
|
|
}
|
|
|
|
);
|
2015-11-04 23:38:22 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
newParent = domainObjectFactory({
|
|
|
|
name: 'newParent',
|
|
|
|
id: '456',
|
|
|
|
model: {
|
|
|
|
composition: []
|
|
|
|
},
|
|
|
|
capabilities: {
|
|
|
|
instantiation: instantiationCapability,
|
|
|
|
persistence: persistenceCapability,
|
|
|
|
composition: compositionCapability
|
|
|
|
}
|
|
|
|
});
|
2015-11-03 02:31:14 +00:00
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
childObject = domainObjectFactory({
|
|
|
|
name: 'childObject',
|
|
|
|
id: 'def',
|
|
|
|
model: {
|
2015-12-03 20:49:54 +00:00
|
|
|
name: 'a child object',
|
|
|
|
location: 'abc'
|
|
|
|
},
|
|
|
|
capabilities: {
|
|
|
|
persistence: persistenceCapability,
|
|
|
|
location: locationCapability
|
2015-06-11 18:58:53 +00:00
|
|
|
}
|
|
|
|
});
|
2015-12-03 20:49:54 +00:00
|
|
|
|
|
|
|
childObjectClone = domainObjectFactory({
|
|
|
|
name: 'childObject',
|
|
|
|
id: 'def.clone',
|
|
|
|
capabilities: {
|
|
|
|
persistence: persistenceCapability,
|
|
|
|
location: locationCapability
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
compositionCapability
|
|
|
|
.invoke
|
2018-06-30 00:32:59 +00:00
|
|
|
.and.returnValue(synchronousPromise([childObject]));
|
2015-11-03 02:31:14 +00:00
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
object = domainObjectFactory({
|
2015-12-03 20:49:54 +00:00
|
|
|
name: 'some object',
|
2015-06-11 18:58:53 +00:00
|
|
|
id: 'abc',
|
|
|
|
model: {
|
|
|
|
name: 'some object',
|
2015-11-04 23:38:22 +00:00
|
|
|
composition: ['def'],
|
|
|
|
location: 'testLocation'
|
2015-06-11 18:58:53 +00:00
|
|
|
},
|
|
|
|
capabilities: {
|
2015-12-03 20:49:54 +00:00
|
|
|
instantiation: instantiationCapability,
|
2015-11-04 23:38:22 +00:00
|
|
|
composition: compositionCapability,
|
2015-12-03 20:49:54 +00:00
|
|
|
location: locationCapability,
|
|
|
|
persistence: persistenceCapability
|
2015-09-22 22:42:39 +00:00
|
|
|
}
|
|
|
|
});
|
2015-12-03 20:49:54 +00:00
|
|
|
|
|
|
|
objectClone = domainObjectFactory({
|
|
|
|
name: 'some object',
|
|
|
|
id: 'abc.clone',
|
2015-11-04 01:39:05 +00:00
|
|
|
capabilities: {
|
2015-12-03 20:49:54 +00:00
|
|
|
instantiation: instantiationCapability,
|
2015-11-04 01:39:05 +00:00
|
|
|
composition: compositionCapability,
|
2015-12-03 20:49:54 +00:00
|
|
|
location: locationCapability,
|
|
|
|
persistence: persistenceCapability
|
2015-06-11 18:58:53 +00:00
|
|
|
}
|
|
|
|
});
|
2015-09-22 22:42:39 +00:00
|
|
|
|
2015-12-03 20:49:54 +00:00
|
|
|
objectClones = [objectClone, childObjectClone];
|
|
|
|
|
|
|
|
copyService = new CopyService(mockQ, policyService);
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
describe("the cloning process", function () {
|
|
|
|
beforeEach(function () {
|
2015-11-04 01:39:05 +00:00
|
|
|
copyResult = copyService.perform(object, newParent);
|
|
|
|
copyFinished = jasmine.createSpy('copyFinished');
|
|
|
|
copyResult.then(copyFinished);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a promise", function () {
|
|
|
|
expect(copyResult.then).toBeDefined();
|
|
|
|
expect(copyFinished).toHaveBeenCalled();
|
|
|
|
});
|
2015-11-03 02:31:14 +00:00
|
|
|
|
2015-12-03 22:47:42 +00:00
|
|
|
it("returns a promise", function () {
|
|
|
|
expect(copyResult.then).toBeDefined();
|
|
|
|
expect(copyFinished).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
it ("correctly locates cloned objects", function () {
|
2015-12-03 20:49:54 +00:00
|
|
|
expect(childObjectClone.getModel().location).toEqual(objectClone.getId());
|
2015-11-04 23:38:22 +00:00
|
|
|
});
|
2015-12-03 22:47:42 +00:00
|
|
|
});
|
2016-02-10 22:31:56 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
describe("when cloning non-creatable objects", function () {
|
2015-12-03 22:47:42 +00:00
|
|
|
beforeEach(function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
policyService.allow.and.callFake(function (category) {
|
2015-12-03 23:28:07 +00:00
|
|
|
//Return false for 'creation' policy
|
2016-05-19 18:29:13 +00:00
|
|
|
return category !== 'creation';
|
2015-12-03 22:47:42 +00:00
|
|
|
});
|
2015-11-04 23:38:22 +00:00
|
|
|
|
2015-12-03 22:47:42 +00:00
|
|
|
copyResult = copyService.perform(object, newParent);
|
|
|
|
copyFinished = jasmine.createSpy('copyFinished');
|
|
|
|
copyResult.then(copyFinished);
|
|
|
|
});
|
2016-05-19 18:29:13 +00:00
|
|
|
it ("creates link instead of clone", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
var copiedObject = copyFinished.calls.all()[0].args[0];
|
2015-12-03 23:28:07 +00:00
|
|
|
expect(copiedObject).toBe(object);
|
2016-02-10 22:21:09 +00:00
|
|
|
expect(compositionCapability.add)
|
|
|
|
.toHaveBeenCalledWith(copiedObject);
|
2015-12-03 22:47:42 +00:00
|
|
|
});
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
2016-02-10 22:31:56 +00:00
|
|
|
|
|
|
|
describe("when provided a filtering function", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
copyFinished = jasmine.createSpy('copyFinished');
|
|
|
|
});
|
|
|
|
|
2016-02-10 22:31:56 +00:00
|
|
|
function accept() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function reject() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
it("does not create new instances of objects " +
|
2016-05-19 18:29:13 +00:00
|
|
|
"rejected by the filter", function () {
|
2016-02-10 22:31:56 +00:00
|
|
|
copyService.perform(object, newParent, reject)
|
|
|
|
.then(copyFinished);
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(copyFinished.calls.mostRecent().args[0])
|
2016-02-10 22:31:56 +00:00
|
|
|
.toBe(object);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does create new instances of objects " +
|
2016-05-19 18:29:13 +00:00
|
|
|
"accepted by the filter", function () {
|
2016-02-10 22:31:56 +00:00
|
|
|
copyService.perform(object, newParent, accept)
|
|
|
|
.then(copyFinished);
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(copyFinished.calls.mostRecent().args[0])
|
2016-02-10 22:31:56 +00:00
|
|
|
.not.toBe(object);
|
|
|
|
});
|
|
|
|
});
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
describe("on invalid inputs", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
object = domainObjectFactory({
|
|
|
|
name: 'object',
|
|
|
|
capabilities: {
|
2015-12-04 00:41:06 +00:00
|
|
|
type: { type: 'object' },
|
|
|
|
location: locationCapability,
|
|
|
|
persistence: persistenceCapability
|
2015-09-23 19:43:03 +00:00
|
|
|
}
|
|
|
|
});
|
2015-12-04 00:41:06 +00:00
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
newParent = domainObjectFactory({
|
|
|
|
name: 'parentCandidate',
|
|
|
|
capabilities: {
|
2015-12-04 00:41:06 +00:00
|
|
|
type: { type: 'parentCandidate' },
|
|
|
|
instantiation: instantiationCapability,
|
|
|
|
composition: compositionCapability,
|
|
|
|
persistence: persistenceCapability
|
2015-09-23 19:43:03 +00:00
|
|
|
}
|
|
|
|
});
|
2015-12-04 00:41:06 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
instantiationCapability.invoke.and.returnValue(object);
|
2015-09-23 19:43:03 +00:00
|
|
|
});
|
2015-09-22 22:49:22 +00:00
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
it("throws an error", function () {
|
2016-05-20 18:39:49 +00:00
|
|
|
var service =
|
2015-12-03 20:49:54 +00:00
|
|
|
new CopyService(mockQ, policyService);
|
2015-09-22 22:49:22 +00:00
|
|
|
|
2015-09-23 19:43:03 +00:00
|
|
|
function perform() {
|
2016-05-20 18:39:49 +00:00
|
|
|
service.perform(object, newParent);
|
2015-09-23 19:43:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 18:39:49 +00:00
|
|
|
spyOn(service, "validate");
|
2018-06-30 00:32:59 +00:00
|
|
|
service.validate.and.returnValue(true);
|
2015-09-23 19:43:03 +00:00
|
|
|
expect(perform).not.toThrow();
|
2018-06-30 00:32:59 +00:00
|
|
|
service.validate.and.returnValue(false);
|
2015-09-23 19:43:03 +00:00
|
|
|
expect(perform).toThrow();
|
|
|
|
});
|
2015-09-22 22:49:22 +00:00
|
|
|
});
|
|
|
|
|
2015-06-11 18:58:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|