123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- /**
- * 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 () {
- }
- });
- beforeEach(function () {
- sinon.spy(controller, "setDBProperty");
- });
- afterEach(function () {
- controller.setDBProperty.restore();
- });
- 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: {}
- }
- ];
- 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;
- });
- });
- });
|