1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312 |
- /**
- * 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');
- require('controllers/wizard');
- require('controllers/main/host/add_controller');
- require('models/host_component');
- require('models/service');
- require('mappers/server_data_mapper');
- describe('App.AddHostController', function () {
- var controller = App.AddHostController.create({
- testDBHosts: null,
- getDBProperty: function () {
- return this.get('testDBHosts');
- },
- setDBProperty: function () {
- },
- loadClients: function () {
- }
- });
- describe('#removeHosts()', function () {
- var testCases = [
- {
- title: 'No hosts, db is empty',
- content: {
- hosts: [],
- dbHosts: {}
- },
- result: {}
- },
- {
- title: 'Host is passed, db is empty',
- content: {
- hosts: [
- {hostName: 'host1'}
- ],
- dbHosts: {}
- },
- result: {}
- },
- {
- title: 'Passed host different from hosts in db',
- content: {
- hosts: [
- {hostName: 'host1'}
- ],
- dbHosts: {
- 'host2': {}
- }
- },
- result: {
- 'host2': {}
- }
- },
- {
- title: 'Passed host match host in db',
- content: {
- hosts: [
- {hostName: 'host1'}
- ],
- dbHosts: {
- 'host1': {}
- }
- },
- result: {}
- }
- ];
- beforeEach(function () {
- sinon.spy(controller, "setDBProperty");
- });
- afterEach(function () {
- controller.setDBProperty.restore();
- });
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('testDBHosts', test.content.dbHosts);
- controller.removeHosts(test.content.hosts);
- expect(controller.setDBProperty.calledWith('hosts', test.result)).to.be.true;
- });
- });
- });
- describe('#sortServiceConfigGroups()', function () {
- var testCases = [
- {
- title: 'No selected services',
- selectedServices: [
- {configGroups: []}
- ],
- result: [
- {configGroups: []}
- ]
- },
- {
- title: 'Only one group is present',
- selectedServices: [
- {configGroups: [
- {configGroups: {group_name: 'b'}}
- ]}
- ],
- result: [
- {configGroups: [
- {configGroups: {group_name: 'b'}}
- ]}
- ]
- },
- {
- title: 'Reverse order of groups',
- selectedServices: [
- {configGroups: [
- {ConfigGroup: {group_name: 'b2'}},
- {ConfigGroup: {group_name: 'a1'}}
- ]}
- ],
- result: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ]
- },
- {
- title: 'Correct order of groups',
- selectedServices: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ],
- result: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ]
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.sortServiceConfigGroups(test.selectedServices);
- expect(test.selectedServices).to.eql(test.result);
- });
- });
- });
- describe('#loadServiceConfigGroupsBySlaves()', function () {
- var testCases = [
- {
- title: 'slaveComponentHosts is null',
- slaveComponentHosts: null,
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'slaveComponentHosts is empty',
- slaveComponentHosts: [],
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Component does not have hosts',
- slaveComponentHosts: [
- {hosts: []}
- ],
- result: {
- output: true,
- selectedServices: []
- }
- },
- {
- title: 'Only client component is present',
- slaveComponentHosts: [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'CLIENT'
- }
- ],
- result: {
- output: true,
- selectedServices: []
- }
- }
- ];
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'HDFS',
- group_name: 'HDFS test'
- }
- }
- ]);
- testCases.forEach(function (test) {
- it(test.title, function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', test.slaveComponentHosts);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.equal(test.result.output);
- expect(selectedServices).to.eql(test.result.selectedServices);
- });
- });
- });
- describe('#loadServiceConfigGroupsByClients()', function () {
- var testCases = [
- {
- title: 'slaveComponentHosts is null',
- content: {
- slaveComponentHosts: null,
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'slaveComponentHosts is empty',
- content: {
- slaveComponentHosts: [],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Client does not have hosts',
- content: {
- slaveComponentHosts: [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Client has hosts, but clients is empty',
- content: {
- slaveComponentHosts: [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('content.slaveComponentHosts', test.content.slaveComponentHosts);
- controller.set('content.clients', test.content.clients);
- expect(controller.loadServiceConfigGroupsByClients(test.content.selectedServices)).to.equal(test.result.output);
- expect(test.content.selectedServices).to.eql(test.result.selectedServices);
- });
- });
- });
- describe('#installServices()', function () {
- beforeEach(function () {
- sinon.spy(App.ajax, "send");
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it('No hosts', function () {
- controller.set('content.cluster', {name: 'cl'});
- controller.set('testDBHosts', {});
- expect(controller.installServices()).to.be.false;
- expect(App.ajax.send.called).to.be.false;
- });
- it('Cluster name is empty', function () {
- controller.set('content.cluster', {name: ''});
- controller.set('testDBHosts', {'host1': {}});
- expect(controller.installServices()).to.be.false;
- expect(App.ajax.send.called).to.be.false;
- });
- it('Cluster name is correct and hosts are present', function () {
- controller.set('content.cluster', {name: 'cl'});
- controller.set('testDBHosts', {'host1': {isInstalled: false}});
- expect(controller.installServices()).to.be.true;
- expect(App.ajax.send.called).to.be.true;
- });
- });
- describe('#getClientsToInstall', function () {
- var services = [
- Em.Object.create({
- serviceName: 'service1'
- }),
- Em.Object.create({
- serviceName: 'service2'
- })
- ];
- var components = [
- Em.Object.create({
- componentName: 'comp1',
- displayName: 'comp1',
- serviceName: 'service1',
- isClient: true
- }),
- Em.Object.create({
- componentName: 'comp2',
- displayName: 'comp2',
- serviceName: 'service1',
- isClient: true
- }),
- Em.Object.create({
- componentName: 'comp3',
- displayName: 'comp3',
- serviceName: 'service2',
- isClient: false
- }),
- Em.Object.create({
- componentName: 'comp4',
- displayName: 'comp4',
- serviceName: 'service3',
- isClient: true
- })
- ];
- var clients = [
- {
- component_name: 'comp1',
- display_name: 'comp1',
- isInstalled: false
- },
- {
- component_name: 'comp2',
- display_name: 'comp2',
- isInstalled: false
- }
- ];
- it("generatel list of clients to install", function () {
- expect(controller.getClientsToInstall(services, components)).to.eql(clients);
- })
- });
- describe("#setCurrentStep()", function () {
- before(function () {
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- sinon.stub(App.db, 'setWizardCurrentStep', Em.K);
- });
- after(function () {
- App.clusterStatus.setClusterStatus.restore();
- App.db.setWizardCurrentStep.restore();
- });
- it("call App.clusterStatus.setClusterStatus()", function () {
- controller.setCurrentStep();
- expect(App.clusterStatus.setClusterStatus.getCall(0).args[0].wizardControllerName).to.be.equal('addHostController');
- });
- });
- describe("#getCluster()", function () {
- before(function () {
- sinon.stub(App.router, 'getClusterName').returns('c1');
- });
- after(function () {
- App.router.getClusterName.restore();
- });
- it("", function () {
- controller.set('clusterStatusTemplate', {'prop': 'clusterStatusTemplate'});
- expect(controller.getCluster()).to.be.eql({
- prop: 'clusterStatusTemplate',
- name: 'c1'
- });
- });
- });
- describe("#getInstallOptions()", function () {
- it("", function () {
- controller.set('installOptionsTemplate', {'prop': 'installOptionsTemplate'});
- expect(controller.getInstallOptions()).to.be.eql({
- prop: 'installOptionsTemplate'
- });
- });
- });
- describe("#loadServices", function () {
- var services = {
- db: null,
- stack: [],
- model: []
- };
- beforeEach(function () {
- sinon.stub(controller, 'getDBProperty', function () {
- return services.db;
- });
- sinon.stub(App.StackService, 'find', function () {
- return services.stack;
- });
- sinon.stub(App.Service, 'find', function () {
- return services.model;
- });
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- afterEach(function () {
- controller.getDBProperty.restore();
- App.StackService.find.restore();
- App.Service.find.restore();
- controller.setDBProperty.restore();
- });
- it("No services in db, no installed services", function () {
- services.stack = [Em.Object.create({
- serviceName: 'S1'
- })];
- controller.loadServices();
- expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
- {
- selectedServices: [],
- installedServices: []
- }
- ]);
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: false,
- isSelected: false
- })
- ])
- });
- it("No services in db, installed service present", function () {
- services.stack = [
- Em.Object.create({
- serviceName: 'S1'
- }),
- Em.Object.create({
- serviceName: 'S2'
- })
- ];
- services.model = [
- Em.Object.create({
- serviceName: 'S1'
- })
- ];
- controller.loadServices();
- expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
- {
- selectedServices: ['S1'],
- installedServices: ['S1']
- }
- ]);
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: true,
- isSelected: true
- }),
- Em.Object.create({
- serviceName: 'S2',
- isInstalled: false,
- isSelected: false
- })
- ]);
- });
- it("DB is empty", function () {
- services.stack = [Em.Object.create({
- serviceName: 'S1'
- })];
- services.db = {
- selectedServices: [],
- installedServices: []
- };
- controller.loadServices();
- expect(controller.setDBProperty.called).to.be.false;
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isSelected: false,
- isInstalled: false
- })
- ]);
- });
- it("DB has selected and installed services", function () {
- services.stack = [
- Em.Object.create({
- serviceName: 'S1'
- }),
- Em.Object.create({
- serviceName: 'S2'
- })
- ];
- services.db = {
- selectedServices: ['S1'],
- installedServices: ['S2']
- };
- controller.loadServices();
- expect(controller.setDBProperty.called).to.be.false;
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: false,
- isSelected: true
- }),
- Em.Object.create({
- serviceName: 'S2',
- isInstalled: true,
- isSelected: false
- })
- ]);
- });
- });
- describe("#loadSlaveComponentHosts()", function () {
- var mock = {
- hosts: null,
- slaveComponentHosts: null
- };
- beforeEach(function () {
- sinon.stub(controller, 'getDBProperty', function (arg) {
- if (arg === 'hosts') return mock.hosts;
- if (arg === 'slaveComponentHosts') return mock.slaveComponentHosts;
- });
- });
- afterEach(function () {
- controller.getDBProperty.restore();
- });
- it("No slaveComponentHosts in db, null", function () {
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.empty;
- });
- it("No slaveComponentHosts in db", function () {
- mock.slaveComponentHosts = [];
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.empty;
- });
- it("One slaveComponent without hosts", function () {
- mock.slaveComponentHosts = [
- {hosts: []}
- ];
- mock.hosts = {};
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.eql([
- {hosts: []}
- ]);
- });
- it("One slaveComponent with host", function () {
- mock.slaveComponentHosts = [
- {hosts: [
- {host_id: 1}
- ]}
- ];
- mock.hosts = {'host1': {id: 1}};
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.eql([
- {hosts: [
- {
- host_id: 1,
- hostName: 'host1'
- }
- ]}
- ]);
- });
- });
- describe("#saveClients()", function () {
- before(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns('StackServiceComponent');
- sinon.stub(controller, 'getClientsToInstall').returns(['client']);
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- after(function () {
- controller.setDBProperty.restore();
- App.StackServiceComponent.find.restore();
- controller.getClientsToInstall.restore();
- });
- it("", function () {
- controller.set('content.services', [Em.Object.create({'isSelected': true})]);
- controller.saveClients();
- expect(controller.getClientsToInstall.calledWith(
- [Em.Object.create({'isSelected': true})],
- 'StackServiceComponent'
- )).to.be.true;
- expect(controller.setDBProperty.calledWith('clientInfo', ['client'])).to.be.true;
- expect(controller.get('content.clients')).to.be.eql(['client']);
- });
- });
- describe("#getClientsToInstall()", function () {
- var testCases = [
- {
- title: 'No services',
- data: {
- services: [],
- components: []
- },
- result: []
- },
- {
- title: 'No components',
- data: {
- services: [
- {}
- ],
- components: []
- },
- result: []
- },
- {
- title: 'Component is not client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({serviceName: 'S1'})]
- },
- result: []
- },
- {
- title: 'Component is not client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({serviceName: 'S1', isClient: false})]
- },
- result: []
- },
- {
- title: 'Component is client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({
- serviceName: 'S1',
- isClient: true,
- componentName: 'C1',
- displayName: 'C1'
- })]
- },
- result: [
- {
- component_name: 'C1',
- display_name: 'C1',
- isInstalled: false
- }
- ]
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- expect(controller.getClientsToInstall(test.data.services, test.data.components)).to.eql(test.result);
- });
- });
- });
- describe("#applyConfigGroup()", function () {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it("No config groups", function () {
- controller.set('content.configGroups', []);
- controller.applyConfigGroup();
- expect(App.ajax.send.called).to.be.false;
- });
- it("selectedConfigGroup absent", function () {
- controller.set('content.configGroups', [
- {
- configGroups: [],
- selectedConfigGroup: ''
- }
- ]);
- controller.applyConfigGroup();
- expect(App.ajax.send.called).to.be.false;
- });
- it("selectedConfigGroup present", function () {
- controller.set('content.configGroups', [
- {
- configGroups: [
- {
- ConfigGroup: {
- id: 1,
- group_name: 'G1',
- hosts: []
- }
- }
- ],
- selectedConfigGroup: 'G1',
- hosts: ['host1']
- }
- ]);
- controller.applyConfigGroup();
- expect(App.ajax.send.getCall(0).args[0].name).to.equal('config_groups.update_config_group');
- expect(App.ajax.send.getCall(0).args[0].data).to.eql({
- "id": 1,
- "configGroup": {
- "ConfigGroup": {
- "id": 1,
- "group_name": "G1",
- "hosts": [
- {
- "host_name": "host1"
- }
- ]
- }
- }
- });
- });
- });
- describe("#getServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'getDBProperty').withArgs('serviceConfigGroups').returns(['serviceConfigGroup']);
- });
- after(function () {
- controller.getDBProperty.restore();
- });
- it("", function () {
- controller.getServiceConfigGroups();
- expect(controller.get('content.configGroups')).to.eql(['serviceConfigGroup']);
- });
- });
- describe("#saveServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- after(function () {
- controller.setDBProperty.restore();
- });
- it("call setDBProperty()", function () {
- controller.set('content.configGroups', [
- {}
- ]);
- controller.saveServiceConfigGroups();
- expect(controller.setDBProperty.calledWith('serviceConfigGroups', [
- {}
- ])).to.be.true;
- });
- });
- describe("#loadServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'loadServiceConfigGroupsBySlaves', Em.K);
- sinon.stub(controller, 'loadServiceConfigGroupsByClients', Em.K);
- sinon.stub(controller, 'sortServiceConfigGroups', Em.K);
- });
- after(function () {
- controller.loadServiceConfigGroupsBySlaves.restore();
- controller.loadServiceConfigGroupsByClients.restore();
- controller.sortServiceConfigGroups.restore();
- });
- it("", function () {
- controller.loadServiceConfigGroups();
- expect(controller.loadServiceConfigGroupsByClients.calledWith([])).to.be.true;
- expect(controller.loadServiceConfigGroupsBySlaves.calledWith([])).to.be.true;
- expect(controller.sortServiceConfigGroups.calledWith([])).to.be.true;
- expect(controller.get('content.configGroups')).to.eql([]);
- });
- });
- describe("#sortServiceConfigGroups", function () {
- var testCases = [
- {
- title: 'sorted',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'a'
- }
- },
- {
- ConfigGroup: {
- group_name: 'b'
- }
- }
- ]
- }
- ],
- result: ['a', 'b']
- },
- {
- title: 'not sorted',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'b'
- }
- },
- {
- ConfigGroup: {
- group_name: 'a'
- }
- }
- ]
- }
- ],
- result: ['a', 'b']
- },
- {
- title: 'sort equal',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'a'
- }
- },
- {
- ConfigGroup: {
- group_name: 'a'
- }
- }
- ]
- }
- ],
- result: ['a', 'a']
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.sortServiceConfigGroups(test.selectedServices);
- expect(test.selectedServices[0].configGroups.mapProperty('ConfigGroup.group_name')).to.eql(test.result);
- });
- });
- });
- describe("#loadServiceConfigGroupsBySlaves()", function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
- stackService: Em.Object.create({
- serviceName: 'S1',
- displayName: 's1'
- })
- }));
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'S1',
- group_name: 'G1'
- }
- }
- ]);
- });
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- });
- it("slaveComponentHosts is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', []);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts has ho hosts", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {hosts: []}
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts is CLIENT", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'CLIENT'
- }
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts is slave", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'C1'
- }
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.eql([
- {
- "serviceId": "S1",
- "displayName": "s1",
- "hosts": [
- "host1"
- ],
- "configGroupsNames": [
- "s1 Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "s1 Default"
- }
- ]);
- });
- });
- describe("#loadServiceConfigGroupsByClients()", function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
- stackService: Em.Object.create({
- serviceName: 'S1',
- displayName: 's1'
- })
- }));
- sinon.stub(controller, 'loadClients', Em.K);
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'S1',
- group_name: 'G1'
- }
- }
- ]);
- });
- afterEach(function () {
- controller.loadClients.restore();
- App.StackServiceComponent.find.restore();
- });
- it("Clients is null", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', null);
- controller.set('content.clients', null);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("No CLIENT component", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', []);
- controller.set('content.clients', []);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Clients is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ]);
- controller.set('content.clients', []);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Client component does not have hosts", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ]);
- controller.set('content.clients', [
- {}
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Client present, selectedServices is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ]);
- controller.set('content.clients', [
- {
- component_name: 'C1'
- }
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
- expect(selectedServices).to.be.eql([
- {
- "serviceId": "S1",
- "displayName": "s1",
- "hosts": [
- "host1"
- ],
- "configGroupsNames": [
- "s1 Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "s1 Default"
- }
- ]);
- });
- it("Client present, selectedServices has service", function () {
- var selectedServices = [
- {
- serviceId: 'S1',
- hosts: ['host1', 'host2']
- }
- ];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ]);
- controller.set('content.clients', [
- {
- component_name: 'C1'
- }
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
- expect(selectedServices[0].hosts).to.be.eql(["host1", "host2"]);
- });
- });
- describe("#loadServiceConfigProperties()", function () {
- beforeEach(function () {
- this.mock = sinon.stub(App.db, 'get');
- this.mock.withArgs('Installer', 'serviceConfigProperties').returns([1]);
- });
- afterEach(function () {
- this.mock.restore();
- });
- it("serviceConfigProperties is null", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns(null);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- it("serviceConfigProperties is empty", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns([]);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- it("serviceConfigProperties has data", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns([1]);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- });
- describe("#loadAllPriorSteps()", function () {
- var stepsSet = {
- '1': [
- {
- name: 'load',
- args: ['hosts']
- },
- {
- name: 'load',
- args: ['installOptions']
- },
- {
- name: 'load',
- args: ['cluster']
- }
- ],
- '2': [
- {
- name: 'loadServices',
- args: []
- }
- ],
- '3': [
- {
- name: 'loadClients',
- args: []
- },
- {
- name: 'loadServices',
- args: []
- },
- {
- name: 'loadMasterComponentHosts',
- args: []
- },
- {
- name: 'loadSlaveComponentHosts',
- args: []
- },
- {
- name: 'load',
- args: ['hosts']
- }
- ],
- '5': [
- {
- name: 'loadServiceConfigProperties',
- args: []
- },
- {
- name: 'getServiceConfigGroups',
- args: []
- }
- ]
- };
- var testCases = [
- {
- currentStep: '0',
- calledFunctions: []
- },
- {
- currentStep: '1',
- calledFunctions: stepsSet['1']
- },
- {
- currentStep: '2',
- calledFunctions: stepsSet['1'].concat(stepsSet['2'])
- },
- {
- currentStep: '3',
- calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
- },
- {
- currentStep: '4',
- calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
- },
- {
- currentStep: '5',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '6',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '7',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '8',
- calledFunctions: []
- }
- ];
- var functionsToCall = [
- 'loadServiceConfigProperties',
- 'getServiceConfigGroups',
- 'loadClients',
- 'loadServices',
- 'loadMasterComponentHosts',
- 'loadSlaveComponentHosts',
- 'load'
- ];
- beforeEach(function () {
- this.mock = sinon.stub(controller, 'get');
- sinon.stub(controller, 'loadServiceConfigProperties', Em.K);
- sinon.stub(controller, 'getServiceConfigGroups', Em.K);
- sinon.stub(controller, 'loadClients', Em.K);
- sinon.stub(controller, 'loadServices', Em.K);
- sinon.stub(controller, 'loadMasterComponentHosts', Em.K);
- sinon.stub(controller, 'loadSlaveComponentHosts', Em.K);
- sinon.stub(controller, 'load', Em.K);
- });
- afterEach(function () {
- this.mock.restore();
- controller.loadServiceConfigProperties.restore();
- controller.getServiceConfigGroups.restore();
- controller.loadClients.restore();
- controller.loadServices.restore();
- controller.loadMasterComponentHosts.restore();
- controller.loadSlaveComponentHosts.restore();
- controller.load.restore();
- });
- testCases.forEach(function (test) {
- it("current step - " + test.currentStep, function () {
- this.mock.returns(test.currentStep);
- controller.loadAllPriorSteps();
- functionsToCall.forEach(function (fName) {
- var callStack = test.calledFunctions.filterProperty('name', fName);
- if (callStack.length > 0) {
- callStack.forEach(function (f, index) {
- expect(controller[f.name].getCall(index).args).to.eql(f.args);
- }, this);
- } else {
- expect(controller[fName].called).to.be.false;
- }
- }, this);
- });
- }, this);
- });
- describe("#clearAllSteps()", function () {
- beforeEach(function () {
- sinon.stub(controller, 'clearInstallOptions', Em.K);
- sinon.stub(controller, 'getCluster').returns({});
- });
- afterEach(function () {
- controller.clearInstallOptions.restore();
- controller.getCluster.restore();
- });
- it("", function () {
- controller.clearAllSteps();
- expect(controller.getCluster.calledOnce).to.be.true;
- expect(controller.clearInstallOptions.calledOnce).to.be.true;
- expect(controller.get('content.cluster')).to.eql({});
- });
- });
- describe("#clearStorageData()", function () {
- beforeEach(function () {
- sinon.stub(controller, 'resetDbNamespace', Em.K);
- });
- afterEach(function () {
- controller.resetDbNamespace.restore();
- });
- it("launch resetDbNamespace", function () {
- controller.clearStorageData();
- expect(controller.resetDbNamespace.calledOnce).to.be.true;
- });
- });
- describe("#finish()", function () {
- var mock = {
- updateAll: Em.K,
- getAllHostNames: Em.K
- };
- beforeEach(function () {
- sinon.stub(controller, 'setCurrentStep', Em.K);
- sinon.stub(controller, 'clearAllSteps', Em.K);
- sinon.stub(controller, 'clearStorageData', Em.K);
- sinon.stub(App.updater, 'immediateRun', Em.K);
- sinon.stub(App.router, 'get').returns(mock);
- sinon.spy(mock, 'updateAll');
- sinon.spy(mock, 'getAllHostNames');
- });
- afterEach(function () {
- controller.setCurrentStep.restore();
- controller.clearAllSteps.restore();
- controller.clearStorageData.restore();
- App.updater.immediateRun.restore();
- App.router.get.restore();
- mock.updateAll.restore();
- mock.getAllHostNames.restore();
- });
- it("", function () {
- controller.finish();
- expect(controller.setCurrentStep.calledWith('1')).to.be.true;
- expect(controller.clearAllSteps.calledOnce).to.be.true;
- expect(controller.clearStorageData.calledOnce).to.be.true;
- expect(mock.updateAll.calledOnce).to.be.true;
- expect(App.updater.immediateRun.calledWith('updateHost')).to.be.true;
- expect(mock.getAllHostNames.calledOnce).to.be.true;
- });
- });
- });
|