| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
- var App = require('app');
- var stringUtils = require('utils/string_utils');
- var numberUtils = require('utils/number_utils');
- var blueprintUtils = require('utils/blueprint');
- var testHelpers = require('test/helpers');
- require('models/stack_service_component');
- describe('App.AssignMasterOnStep7Controller', function () {
- var view;
- beforeEach(function () {
- view = App.AssignMasterOnStep7Controller.create();
- });
- describe("#content", function () {
- it("content is correct", function () {
- view.set('configWidgetContext.controller', Em.Object.create({
- content: {'name': 'name'}
- }));
- view.propertyDidChange('content');
- expect(view.get('content')).to.be.eql({'name': 'name'});
- });
- it("content is null", function () {
- view.set('configWidgetContext.controller', Em.Object.create({
- content: null
- }));
- view.propertyDidChange('content');
- expect(view.get('content')).to.be.empty;
- });
- });
- describe("#execute()", function () {
- var context = Em.Object.create({
- controller: {
- content: {}
- }
- });
- beforeEach(function() {
- sinon.stub(view, 'showPopup');
- sinon.stub(view, 'removeMasterComponent');
- sinon.stub(view, 'getPendingBatchRequests');
- });
- afterEach(function() {
- view.getPendingBatchRequests.restore();
- view.showPopup.restore();
- view.removeMasterComponent.restore();
- });
- it("should set configWidgetContext", function() {
- view.execute(context, 'ADD', {componentName: 'C1'});
- expect(view.get('configWidgetContext')).to.be.eql(context);
- });
- it("should set content", function() {
- view.execute(context, 'ADD', {componentName: 'C1'});
- expect(view.get('content')).to.be.eql({});
- });
- it("should set configActionComponent", function() {
- view.execute(context, 'ADD', {componentName: 'C1'});
- expect(view.get('configActionComponent')).to.be.eql({componentName: 'C1'});
- });
- it("should call showPopup when action is ADD", function() {
- view.execute(context, 'ADD', {componentName: 'C1'});
- expect(view.showPopup.calledWith({componentName: 'C1'})).to.be.true;
- });
- it("should call getPendingBatchRequests when action is ADD and HIVE_SERVER_INTERACTIVE", function() {
- view.execute(context, 'ADD', {componentName: 'HIVE_SERVER_INTERACTIVE'});
- expect(view.getPendingBatchRequests.calledWith({componentName: 'HIVE_SERVER_INTERACTIVE'})).to.be.true;
- });
- it("should call removeMasterComponent when action is DELETE", function() {
- view.execute(context, 'DELETE', {componentName: 'C1'});
- expect(view.removeMasterComponent.calledOnce).to.be.true;
- expect(view.get('mastersToCreate')).to.be.eql(['C1']);
- });
- });
- describe("#showAssignComponentPopup()", function () {
- beforeEach(function() {
- sinon.stub(view, 'loadMasterComponentHosts');
- sinon.stub(App.ModalPopup, 'show');
- });
- afterEach(function() {
- view.loadMasterComponentHosts.restore();
- App.ModalPopup.show.restore();
- });
- it("loadMasterComponentHosts should be called", function() {
- view.reopen({
- content: {
- controllerName: null
- }
- });
- view.showAssignComponentPopup();
- expect(view.loadMasterComponentHosts.calledOnce).to.be.true;
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- it("loadMasterComponentHosts should not be called", function() {
- view.reopen({
- content: {
- controllerName: 'ctrl1'
- }
- });
- view.showAssignComponentPopup();
- expect(view.loadMasterComponentHosts.called).to.be.false;
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- });
- describe("#showInstallServicesPopup()", function () {
- var mock = Em.Object.create({
- config: Em.Object.create({
- initialValue: 'init',
- value: '',
- displayName: 'c1'
- }),
- setValue: Em.K,
- toggleProperty: Em.K,
- sendRequestRorDependentConfigs: Em.K
- });
- beforeEach(function() {
- sinon.stub(stringUtils, 'getFormattedStringFromArray');
- sinon.stub(mock, 'setValue');
- sinon.stub(mock, 'toggleProperty');
- sinon.stub(mock, 'sendRequestRorDependentConfigs');
- sinon.spy(App.ModalPopup, 'show');
- });
- afterEach(function() {
- stringUtils.getFormattedStringFromArray.restore();
- mock.setValue.restore();
- mock.toggleProperty.restore();
- mock.sendRequestRorDependentConfigs.restore();
- App.ModalPopup.show.restore();
- });
- it("test", function() {
- view.set('configWidgetContext', mock);
- var popup = view.showInstallServicesPopup();
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- popup.onPrimary();
- expect(mock.get('config.value')).to.be.equal('init');
- expect(mock.setValue.calledWith('init')).to.be.true;
- });
- });
- describe("#removeMasterComponent()", function () {
- var mock = {
- setDBProperty: Em.K
- };
- beforeEach(function() {
- sinon.stub(App.router, 'get').returns(mock);
- sinon.stub(mock, 'setDBProperty');
- sinon.stub(view, 'clearComponentsToBeAdded');
- sinon.stub(App.HostComponent, 'find').returns([
- Em.Object.create({
- componentName: 'C1',
- hostName: 'host1'
- })
- ]);
- });
- afterEach(function() {
- App.router.get.restore();
- mock.setDBProperty.restore();
- view.clearComponentsToBeAdded.restore();
- App.HostComponent.find.restore();
- });
- it("should set masterComponentHosts", function() {
- view.reopen({
- content: Em.Object.create({
- controllerName: 'ctrl1',
- masterComponentHosts: [
- {component: 'C1'},
- {component: 'C2'}
- ],
- componentsFromConfigs: ["C1","C2"],
- recommendationsHostGroups: {
- blueprint: {host_groups: [{name: 'host-group-1', components: [{name: 'C1'}, {name: 'C2'}]}]},
- blueprint_cluster_binding: {host_groups: [{name: 'host-group-1', hosts: [{fqdn: 'localhost'}]}]}
- }
- }),
- configWidgetContext: {
- config: Em.Object.create()
- }
- });
- view.set('mastersToCreate', ['C2']);
- view.removeMasterComponent();
- expect(view.get('content.masterComponentHosts')).to.be.eql([{component: 'C1'}]);
- expect(view.get('content.recommendationsHostGroups').blueprint).to.be.eql({host_groups: [{name: 'host-group-1', components: [{name: 'C1'}]}]});
- });
- it("should call clearComponentsToBeAdded when controllerName is null", function() {
- view.setProperties({
- content: Em.Object.create(),
- mastersToCreate: ['C1'],
- configWidgetContext: {
- config: Em.Object.create()
- }
- });
- view.removeMasterComponent();
- expect(view.clearComponentsToBeAdded.calledWith('C1')).to.be.true;
- expect(App.get('componentToBeDeleted')).to.be.eql(Em.Object.create({
- componentName: 'C1',
- hostName: 'host1'
- }));
- });
- });
- describe("#renderHostInfo()", function () {
- beforeEach(function() {
- sinon.stub(view, 'getHosts').returns([]);
- });
- afterEach(function() {
- view.getHosts.restore();
- });
- it("should make general request to get hosts", function() {
- view.reopen({
- content: Em.Object.create({
- controllerName: 'name'
- })
- });
- view.renderHostInfo();
- var args = testHelpers.findAjaxRequest('name', 'hosts.high_availability.wizard');
- expect(args).exists;
- });
- it("should make request for installer to get hosts", function() {
- view.reopen({
- content: Em.Object.create({
- controllerName: 'installerController'
- })
- });
- view.renderHostInfo();
- var args = testHelpers.findAjaxRequest('name', 'hosts.info.install');
- expect(args).exists;
- });
- });
- describe("#loadMasterComponentHosts()", function () {
- beforeEach(function() {
- sinon.stub(App.HostComponent, 'find').returns([
- Em.Object.create({
- componentName: 'C1'
- }),
- Em.Object.create({
- componentName: 'C2'
- })
- ]);
- sinon.stub(App, 'get').returns(['C2']);
- });
- afterEach(function() {
- App.get.restore();
- App.HostComponent.find.restore();
- });
- it("should set master components", function() {
- view.loadMasterComponentHosts();
- expect(view.get('masterComponentHosts').mapProperty('component')).to.be.eql(['C2']);
- });
- });
- describe("#getAllMissingDependentServices()", function () {
- beforeEach(function() {
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
- stackService: Em.Object.create({
- requiredServices: ['S1', 'S2']
- })
- }));
- sinon.stub(App.Service, 'find').returns([
- {serviceName: 'S1'}
- ]);
- sinon.stub(App.StackService, 'find', function(input) {
- return Em.Object.create({displayName: input});
- });
- });
- afterEach(function() {
- App.StackServiceComponent.find.restore();
- App.Service.find.restore();
- App.StackService.find.restore();
- });
- it("test", function() {
- view.set('configActionComponent', Em.Object.create({
- componentName: 'C1'
- }));
- expect(view.getAllMissingDependentServices()).to.be.eql(['S2']);
- });
- });
- describe('#getPendingBatchRequests', function() {
- it('App.ajax.send should be called', function() {
- view.getPendingBatchRequests({componentName: 'C1'});
- var args = testHelpers.findAjaxRequest('name', 'request_schedule.get.pending');
- expect(args[0]).to.be.eql({
- name : 'request_schedule.get.pending',
- sender: view,
- error : 'pendingBatchRequestsAjaxError',
- success: 'pendingBatchRequestsAjaxSuccess',
- data: {
- hostComponent: {componentName: 'C1'}
- }
- });
- });
- });
- describe('#pendingBatchRequestsAjaxError', function() {
- beforeEach(function() {
- sinon.stub(App, 'showAlertPopup');
- });
- afterEach(function() {
- App.showAlertPopup.restore();
- });
- it('should call showAlertPopup, invalid JSON', function() {
- view.pendingBatchRequestsAjaxError({responseText: null});
- expect(App.showAlertPopup.calledWith(
- Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'),
- Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'),
- null
- )).to.be.true;
- });
- it('should call showAlertPopup, valid JSON', function() {
- view.pendingBatchRequestsAjaxError({responseText: '{"message":"foo"}'});
- expect(App.showAlertPopup.calledWith(
- Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'),
- Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error') + 'foo',
- null
- )).to.be.true;
- });
- });
- describe('#pendingBatchRequestsAjaxSuccess', function() {
- var configWidgetContext = Em.Object.create({
- config: Em.Object.create({
- initialValue: 'iv1',
- value: 'v1'
- }),
- controller: {
- forceUpdateBoundaries: false
- },
- setValue: sinon.spy(),
- sendRequestRorDependentConfigs: sinon.spy()
- });
- beforeEach(function() {
- this.mock = sinon.stub(view, 'shouldShowAlertOnBatchRequest');
- sinon.stub(App, 'showAlertPopup', function() {
- arguments[2].apply({hide: Em.K});
- });
- sinon.stub(view, 'showPopup');
- view.set('configWidgetContext', configWidgetContext);
- });
- afterEach(function() {
- this.mock.restore();
- App.showAlertPopup.restore();
- view.showPopup.restore();
- });
- it('showPopup should be called', function() {
- this.mock.returns(false);
- view.pendingBatchRequestsAjaxSuccess({}, {}, {hostComponent: {componentName: 'C1'}});
- expect(view.showPopup.calledWith({componentName: 'C1'})).to.be.true;
- });
- describe('showAlertPopup should be called', function() {
- beforeEach(function() {
- this.mock.returns(true);
- view.pendingBatchRequestsAjaxSuccess({}, {}, {hostComponent: {componentName: 'C1'}});
- });
- it('App.showAlertPopup is called', function () {
- expect(App.showAlertPopup.calledWith(
- Em.I18n.t('services.service.actions.hsi.alertPopup.header'),
- Em.I18n.t('services.service.actions.hsi.alertPopup.body')
- )).to.be.true;
- });
- it('config value is correct', function () {
- expect(configWidgetContext.get('config.value')).to.be.equal('iv1');
- });
- it('forceUpdateBoundaries is true', function () {
- expect(configWidgetContext.get('controller.forceUpdateBoundaries')).to.be.true;
- });
- it('configWidgetContext.setValue is called', function () {
- expect(configWidgetContext.setValue.calledWith('iv1')).to.be.true;
- });
- it('configWidgetContext.sendRequestRorDependentConfigs is called', function () {
- expect(configWidgetContext.sendRequestRorDependentConfigs.calledWith(
- configWidgetContext.get('config')
- )).to.be.true;
- });
- });
- });
- describe('#shouldShowAlertOnBatchRequest', function() {
- var testCases = [
- {
- input: {},
- expected: false
- },
- {
- input: {
- items: []
- },
- expected: false
- },
- {
- input: {
- items: [
- {
- RequestSchedule: {
- batch: {
- batch_requests: [
- {
- request_type: 'ADD',
- request_uri: ''
- }
- ]
- }
- }
- }
- ]
- },
- expected: false
- },
- {
- input: {
- items: [
- {
- RequestSchedule: {
- batch: {
- batch_requests: [
- {
- request_type: 'DELETE',
- request_uri: 'HIVE_SERVER_INTERACTIVE'
- }
- ]
- }
- }
- }
- ]
- },
- expected: true
- }
- ];
- testCases.forEach(function(test) {
- it('should return ' + test.expected + ' when data = ' + JSON.stringify(test.input), function() {
- expect(view.shouldShowAlertOnBatchRequest(test.input)).to.be.equal(test.expected);
- });
- });
- });
- describe('#updateComponent and showAddControl should be false for component', function() {
- beforeEach(function() {
- sinon.stub(App.StackServiceComponent, 'find').returns([
- Em.Object.create({
- componentName: 'C1',
- stackService: Em.Object.create({
- isInstalled: false
- })
- })
- ]);
- });
- afterEach(function() {
- App.StackServiceComponent.find.restore();
- });
- it('showRemoveControl ', function() {
- var component = Em.Object.create({
- component_name: 'C1',
- showAddControl: true,
- showRemoveControl: true
- });
- view.setProperties({
- mastersToCreate: [],
- selectedServicesMasters: [ component, {component_name: 'C2'} ]
- });
- view.updateComponent('C1');
- expect(component.get('showAddControl')).to.be.false;
- expect(component.get('showRemoveControl')).to.be.false;
- });
- });
- describe('#saveRecommendationsHostGroups', function() {
- beforeEach(function() {
- sinon.stub(view, 'getSelectedHostName').returns('host1');
- });
- afterEach(function() {
- view.getSelectedHostName.restore();
- });
- it('should add component to recommendations', function() {
- var recommendationsHostGroups = {
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: 'g1',
- hosts: [
- {
- fqdn: 'host1'
- }
- ]
- }
- ]
- },
- blueprint: {
- host_groups: [
- {
- name: 'g1',
- components: []
- }
- ]
- }
- };
- view.reopen({
- mastersToCreate: ['C1'],
- content: Em.Object.create({
- recommendationsHostGroups: recommendationsHostGroups
- })
- });
- view.saveRecommendationsHostGroups();
- expect(view.get('content.recommendationsHostGroups')).to.be.eql(Object.assign(recommendationsHostGroups, {
- blueprint: {
- host_groups: [
- {
- name: 'g1',
- components: [{name: 'C1'}]
- }
- ]
- }
- }));
- });
- });
- describe('#setGlobalComponentToBeAdded', function() {
- it('should set componentToBeAdded', function() {
- view.setGlobalComponentToBeAdded('C1', 'host1');
- expect(App.get('componentToBeAdded')).to.be.eql(Em.Object.create({
- componentName: 'C1',
- hostNames: ['host1']
- }));
- });
- });
- describe('#clearComponentsToBeDeleted', function() {
- it('should clear componentToBeDeleted', function() {
- App.set('componentToBeDeleted', Em.Object.create({
- componentName: 'C1'
- }));
- view.clearComponentsToBeDeleted('C1');
- expect(App.get('componentToBeDeleted')).to.be.empty;
- });
- });
- describe('#clearComponentsToBeAdded', function() {
- it('should clear componentToBeAdded', function() {
- App.set('componentToBeAdded', Em.Object.create({
- componentName: 'C1'
- }));
- view.clearComponentsToBeAdded('C1');
- expect(App.get('componentToBeAdded')).to.be.empty;
- });
- });
- describe('#showPopup', function() {
- beforeEach(function() {
- this.mock = sinon.stub(view, 'getAllMissingDependentServices');
- sinon.stub(view, 'showInstallServicesPopup');
- sinon.stub(view, 'showAssignComponentPopup');
- });
- afterEach(function() {
- this.mock.restore();
- view.showInstallServicesPopup.restore();
- view.showAssignComponentPopup.restore();
- });
- it('showAssignComponentPopup should be called', function() {
- this.mock.returns([]);
- view.showPopup({componentName: 'C1'});
- expect(view.get('mastersToCreate')).to.be.eql(['C1']);
- expect(view.showAssignComponentPopup.calledOnce).to.be.true;
- });
- it('showInstallServicesPopup should be called', function() {
- this.mock.returns([{}]);
- view.reopen({
- content: Em.Object.create()
- });
- view.showPopup({componentName: 'C1'});
- expect(view.showInstallServicesPopup.calledWith([{}])).to.be.true;
- });
- });
- describe('#submit', function() {
- var configWidgetContext = Em.Object.create({
- controller: {
- forceUpdateBoundaries: false,
- stepConfigs: [
- Em.Object.create({
- serviceName: 'S1',
- configs: []
- }),
- Em.Object.create({
- serviceName: 'MISC',
- configs: []
- })
- ],
- selectedService: {
- serviceName: 'S1'
- }
- },
- config: Em.Object.create({
- configAction: {
- dependencies: []
- }
- })
- });
- beforeEach(function() {
- sinon.stub(view, 'resolveDependencies');
- sinon.stub(view, 'saveMasterComponentHosts');
- sinon.stub(view, 'saveRecommendationsHostGroups');
- sinon.stub(view, 'setGlobalComponentToBeAdded');
- sinon.stub(view, 'clearComponentsToBeDeleted');
- sinon.stub(App, 'get').returns({
- getKDCSessionState: Em.clb
- });
- sinon.stub(view, 'getSelectedHostName').returns('host1');
- view.setProperties({
- configWidgetContext: configWidgetContext,
- configActionComponent: { componentName: 'C1'},
- popup: {
- hide: sinon.spy()
- }
- });
- });
- afterEach(function() {
- App.get.restore();
- view.resolveDependencies.restore();
- view.clearComponentsToBeDeleted.restore();
- view.setGlobalComponentToBeAdded.restore();
- view.saveRecommendationsHostGroups.restore();
- view.saveMasterComponentHosts.restore();
- view.getSelectedHostName.restore();
- });
- it('saveMasterComponentHosts should be called when controllerName defined', function() {
- view.reopen({
- content: {
- controllerName: 'ctrl1'
- }
- });
- view.submit();
- expect(view.saveMasterComponentHosts.calledOnce).to.be.true;
- });
- it('saveRecommendationsHostGroups should be called when controllerName defined', function() {
- view.reopen({
- content: {
- controllerName: 'ctrl1'
- }
- });
- view.submit();
- expect(view.saveRecommendationsHostGroups.calledOnce).to.be.true;
- });
- it('setGlobalComponentToBeAdded should be called when controllerName undefined', function() {
- view.reopen({
- content: {
- controllerName: undefined
- }
- });
- view.submit();
- expect(view.setGlobalComponentToBeAdded.calledWith('C1', 'host1')).to.be.true;
- });
- it('clearComponentsToBeDeleted should be called when controllerName undefined', function() {
- view.reopen({
- content: {
- controllerName: undefined
- }
- });
- view.submit();
- expect(view.clearComponentsToBeDeleted.calledWith('C1')).to.be.true;
- });
- it('resolveDependencies should be called', function() {
- view.submit();
- expect(view.resolveDependencies.calledWith([], [])).to.be.true;
- });
- it('hide should be called', function() {
- view.submit();
- expect(view.get('popup').hide.calledOnce).to.be.true;
- });
- it('configActionComponent should be set', function() {
- view.submit();
- expect(view.get('configWidgetContext.config.configActionComponent')).to.be.eql({
- componentName: 'C1',
- hostName: 'host1'
- });
- });
- });
- describe('#resolveDependencies', function() {
- var initializer = {
- setup: sinon.spy(),
- initialValue: sinon.stub().returns({value: 'val1'}),
- cleanup: sinon.spy()
- };
- var dependencies = {
- properties: [
- {
- name: 'p1',
- fileName: 'file1.xml',
- nameTemplate: '{{bar}}',
- isHostsList: true,
- isHostsArray: false
- }
- ],
- initializer: {
- name: 'i1',
- setupKeys: ['bar']
- }
- };
- var context = Em.Object.create({
- controller: {
- selectedService: {
- serviceName: 'S1'
- }
- }
- });
- var serviceConfigs = [
- Em.Object.create({
- name: 'foo',
- filename: 'file1.xml',
- value: 'val1'
- })
- ];
- beforeEach(function() {
- sinon.stub(view, 'getDependenciesForeignKeys').returns({
- bar: 'foo'
- });
- sinon.stub(App, 'get').returns(initializer);
- sinon.stub(view, 'getMasterComponents');
- sinon.stub(view, 'saveRecommendations');
- sinon.stub(App.config, 'updateHostsListValue');
- sinon.stub(App.config, 'get').returns({
- 'file1.xml': Em.Object.create({
- serviceName: 'S1'
- })
- });
- view.resolveDependencies(dependencies, serviceConfigs, context);
- });
- afterEach(function() {
- App.config.get.restore();
- view.getDependenciesForeignKeys.restore();
- App.get.restore();
- view.getMasterComponents.restore();
- view.saveRecommendations.restore();
- App.config.updateHostsListValue.restore();
- });
- it('initializer.setup should be called', function() {
- expect(initializer.setup.calledWith({bar: 'foo'})).to.be.true;
- });
- it('initializer.setup initialValue be called', function() {
- expect(initializer.initialValue.calledWith({
- name: 'foo',
- fileName: 'file1.xml'
- })).to.be.true;
- });
- it('initializer.cleanup should be called', function() {
- expect(initializer.cleanup.called).to.be.true;
- });
- it('saveRecommendations should be called', function() {
- expect(view.saveRecommendations.calledWith(context)).to.be.true;
- });
- it('App.config.updateHostsListValue should be called', function() {
- expect(App.config.updateHostsListValue.getCall(0).args).to.be.eql([
- {
- foo: 'val1'
- },
- 'file1.xml',
- 'foo',
- undefined,
- false
- ]);
- });
- });
- describe('#saveMasterComponentHosts', function() {
- var mockCtrl = {
- saveMasterComponentHosts: sinon.spy(),
- loadMasterComponentHosts: sinon.spy()
- };
- beforeEach(function() {
- sinon.stub(App.router, 'get').returns(mockCtrl);
- view.reopen({
- content: Em.Object.create({
- componentsFromConfigs: []
- })
- });
- view.set('mastersToCreate', [
- {}
- ]);
- });
- afterEach(function() {
- App.router.get.restore();
- });
- it('saveMasterComponentHosts should be called', function() {
- view.saveMasterComponentHosts();
- expect(mockCtrl.saveMasterComponentHosts.calledWith(view, true)).to.be.true;
- });
- it('loadMasterComponentHosts should be called', function() {
- view.saveMasterComponentHosts();
- expect(mockCtrl.loadMasterComponentHosts.calledWith(true)).to.be.true;
- });
- it('componentsFromConfigs should be set', function() {
- view.saveMasterComponentHosts();
- expect(view.get('content.componentsFromConfigs')).to.be.eql([{}]);
- });
- });
- describe('#getSelectedHostName', function() {
- it('should return host of component', function() {
- view.set('selectedServicesMasters', [
- {
- component_name: 'C1',
- selectedHost: 'host1'
- }
- ]);
- expect(view.getSelectedHostName('C1')).to.be.equal('host1');
- });
- });
- describe('#saveRecommendations', function() {
- var mockCtrl = {
- loadRecommendationsSuccess: sinon.spy(),
- wizardController: {
- name: 'installerController'
- }
- };
- var context = Em.Object.create({
- controller: mockCtrl
- });
- it('loadRecommendationsSuccess should be called', function() {
- view.set('configWidgetContext', {
- config: Em.Object.create({
- fileName: 'foo.xml',
- name: 'bar',
- initialValue: 'iv1'
- })
- });
- view.saveRecommendations(context, {});
- expect(mockCtrl.loadRecommendationsSuccess.getCall(0).args).to.be.eql([
- {
- resources: [
- {
- recommendations: {
- blueprint: {
- configurations: {}
- }
- }
- }
- ]
- }, null, {
- dataToSend: {
- changed_configurations: [{
- type: 'foo',
- name: 'bar',
- old_value: 'iv1'
- }]
- }
- }
- ]);
- });
- });
- describe('#getDependenciesForeignKeys', function() {
- var dependencies = {
- foreignKeys: [
- {
- fileName: 'foo.xml',
- propertyName: 'c1',
- key: 'k1'
- }
- ]
- };
- var serviceConfigs = [
- Em.Object.create({
- filename: 'foo.xml',
- name: 'c1',
- value: 'val1'
- })
- ];
- it('should return foreignKeys map', function() {
- expect(view.getDependenciesForeignKeys(dependencies, serviceConfigs)).to.be.eql({
- k1: 'val1'
- });
- });
- });
- describe('#getMasterComponents', function() {
- var dependencies = {
- initializer: {
- componentNames: ['C1']
- }
- };
- var context = Em.Object.create({
- controller: {
- content: {
- masterComponentHosts: [
- {
- component: 'C1',
- hostName: 'host2'
- }
- ]
- }
- }
- });
- beforeEach(function() {
- sinon.stub(blueprintUtils, 'getComponentForHosts').returns({
- host1: ['C1']
- });
- });
- afterEach(function() {
- blueprintUtils.getComponentForHosts.restore();
- });
- it('should return master components when controllerName undefined', function() {
- view.set('content.controllerName', undefined);
- expect(view.getMasterComponents(dependencies, context)).to.be.eql([
- {
- component: 'C1',
- hostName: 'host1',
- isInstalled: true
- }
- ]);
- });
- it('should return master components when controllerName valid', function() {
- view.set('content.controllerName', 'ctrl1');
- expect(view.getMasterComponents(dependencies, context)).to.be.eql([
- {
- component: 'C1',
- hostName: 'host2',
- isInstalled: true
- }
- ]);
- });
- });
- });
|