123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- /**
- * 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/main/admin/security/security_progress_controller');
- require('models/host_component');
- require('models/host');
- describe('App.MainAdminSecurityProgressController', function () {
- var controller = App.MainAdminSecurityProgressController.create({
- loadClusterConfigs: function () {},
- deleteComponents: function () {}
- });
- describe('#retry()', function () {
- beforeEach(function () {
- sinon.spy(controller, "startCommand");
- });
- afterEach(function () {
- controller.startCommand.restore();
- });
- it('commands are empty', function () {
- controller.set('commands', []);
- controller.retry();
- expect(controller.startCommand.called).to.be.false;
- });
- it('command is successful', function () {
- controller.set('commands', [
- Em.Object.create({
- name: 'test',
- isSuccess: true,
- isError: false,
- isStarted: true
- })
- ]);
- controller.retry();
- expect(controller.startCommand.calledOnce).to.be.false;
- expect(controller.get('commands').findProperty('name', 'test').get('isError')).to.be.false;
- expect(controller.get('commands').findProperty('name', 'test').get('isStarted')).to.be.true;
- });
- it('command is failed', function () {
- controller.set('commands', [
- Em.Object.create({
- name: 'test',
- isSuccess: true,
- isError: true,
- isStarted: true
- })
- ]);
- controller.retry();
- expect(controller.startCommand.calledOnce).to.be.true;
- expect(controller.get('commands').findProperty('name', 'test').get('isError')).to.be.false;
- expect(controller.get('commands').findProperty('name', 'test').get('isStarted')).to.be.false;
- });
- });
- describe('#updateServices()', function () {
- it('commands are empty', function () {
- controller.set('services', [
- {}
- ]);
- controller.set('commands', []);
- controller.updateServices();
- expect(controller.get('services')).to.be.empty;
- });
- it('command doesn\'t have polledData', function () {
- controller.set('services', [
- {}
- ]);
- controller.set('commands', [Em.Object.create({
- label: 'label'
- })]);
- controller.updateServices();
- expect(controller.get('services')).to.be.empty;
- });
- it('command has polledData', function () {
- controller.set('services', [
- {}
- ]);
- controller.set('commands', [Em.Object.create({
- label: 'service1',
- polledData: [
- {
- Tasks: {
- host_name: 'host1'
- }
- }
- ]
- })]);
- controller.updateServices();
- expect(controller.get('services').findProperty('name', 'service1').get('hosts')).to.eql([
- {
- name: 'host1',
- publicName: 'host1',
- logTasks: [
- {
- Tasks: {host_name: 'host1'}
- }
- ]
- }
- ]);
- });
- });
- describe('#setIndex()', function () {
- it('commandArray is empty', function () {
- var commandArray = [];
- controller.setIndex(commandArray);
- expect(commandArray).to.be.empty;
- expect(controller.get('totalSteps')).to.equal(0);
- });
- it('one command in commandArray', function () {
- var commandArray = [
- Em.Object.create({name: 'command1'})
- ];
- controller.setIndex(commandArray);
- expect(commandArray[0].get('index')).to.equal(1);
- expect(controller.get('totalSteps')).to.equal(1);
- });
- it('commands with random indexes', function () {
- var commandArray = [];
- commandArray[3] = Em.Object.create({name: 'command3'});
- commandArray[11] = Em.Object.create({name: 'command11'});
- controller.setIndex(commandArray);
- expect(commandArray[3].get('index')).to.equal(4);
- expect(commandArray[11].get('index')).to.equal(12);
- expect(controller.get('totalSteps')).to.equal(12);
- });
- });
- describe('#startCommand()', function () {
- var command = Em.Object.create({
- start: Em.K
- });
- beforeEach(function () {
- sinon.spy(command, "start");
- sinon.spy(controller, "loadClusterConfigs");
- sinon.spy(controller, "deleteComponents");
- sinon.stub(controller, "saveCommands", Em.K);
- });
- afterEach(function () {
- command.start.restore();
- controller.loadClusterConfigs.restore();
- controller.deleteComponents.restore();
- controller.saveCommands.restore();
- });
- it('number of commands doesn\'t match totalSteps', function () {
- controller.set('commands', []);
- controller.set('totalSteps', 1);
- expect(controller.startCommand()).to.be.false;
- });
- it('commands is empty', function () {
- controller.set('commands', []);
- controller.set('totalSteps', 0);
- expect(controller.startCommand()).to.be.false;
- });
- it('command is started and completed', function () {
- controller.set('commands', [Em.Object.create({
- isStarted: true,
- isCompleted: true
- })]);
- controller.set('totalSteps', 1);
- expect(controller.startCommand()).to.be.false;
- });
- it('command is started and incompleted', function () {
- controller.set('commands', [Em.Object.create({
- isStarted: true,
- isCompleted: false
- })]);
- controller.set('totalSteps', 1);
- expect(controller.startCommand()).to.be.true;
- });
- it('command parameter passed, isPolling is true', function () {
- controller.set('commands', []);
- controller.set('totalSteps', 0);
- command.set('isPolling', true);
- expect(controller.startCommand(command)).to.be.true;
- expect(command.get('isStarted')).to.be.true;
- expect(command.start.calledOnce).to.be.true;
- command.set('isPolling', false);
- });
- it('command parameter passed, name is "APPLY_CONFIGURATIONS"', function () {
- command.set('name', 'APPLY_CONFIGURATIONS');
- expect(controller.startCommand(command)).to.be.true;
- expect(command.get('isStarted')).to.be.true;
- expect(controller.loadClusterConfigs.calledOnce).to.be.true;
- });
- it('command parameter passed, name is "DELETE_ATS"', function () {
- command.set('name', 'DELETE_ATS');
- sinon.stub(App.HostComponent, 'find', function() {
- return [Em.Object.create({
- id: 'APP_TIMELINE_SERVER_ats_host',
- componentName: 'APP_TIMELINE_SERVER',
- hostName: 'ats_host'
- })];
- });
- expect(controller.startCommand(command)).to.be.true;
- expect(command.get('isStarted')).to.be.true;
- expect(controller.deleteComponents.calledWith('APP_TIMELINE_SERVER', 'ats_host')).to.be.true;
- App.HostComponent.find.restore();
- });
- });
- describe('#onCompleteCommand()', function () {
- beforeEach(function () {
- sinon.spy(controller, "moveToNextCommand");
- sinon.stub(controller, "saveCommands", Em.K);
- });
- afterEach(function () {
- controller.moveToNextCommand.restore();
- controller.saveCommands.restore();
- });
- it('number of commands doesn\'t match totalSteps', function () {
- controller.set('commands', []);
- controller.set('totalSteps', 1);
- expect(controller.onCompleteCommand()).to.be.false;
- });
- it('No successful commands', function () {
- controller.set('commands', [Em.Object.create({
- isSuccess: false
- })]);
- controller.set('totalSteps', 1);
- expect(controller.onCompleteCommand()).to.be.false;
- });
- it('No successful commands', function () {
- controller.set('commands', [Em.Object.create({
- isSuccess: false
- })]);
- controller.set('totalSteps', 1);
- expect(controller.onCompleteCommand()).to.be.false;
- });
- it('Last command is successful', function () {
- controller.set('commands', [
- Em.Object.create({
- isSuccess: false
- }),
- Em.Object.create({
- isSuccess: true
- })
- ]);
- controller.set('totalSteps', 2);
- expect(controller.onCompleteCommand()).to.be.false;
- });
- it('all commands are successful', function () {
- controller.set('commands', [
- Em.Object.create({
- isSuccess: true,
- name: 'command1'
- }),
- Em.Object.create({
- isSuccess: false,
- name: 'command2'
- })
- ]);
- controller.set('totalSteps', 2);
- expect(controller.onCompleteCommand()).to.be.true;
- expect(controller.moveToNextCommand.calledWith(Em.Object.create({
- isSuccess: false,
- name: 'command2'
- }))).to.be.true;
- });
- });
- describe('#moveToNextCommand()', function () {
- beforeEach(function () {
- sinon.spy(controller, "startCommand");
- });
- afterEach(function () {
- controller.startCommand.restore();
- });
- it('No commands present', function () {
- controller.set('commands', []);
- expect(controller.moveToNextCommand()).to.be.false;
- });
- it('Only started command present', function () {
- controller.set('commands', [
- Em.Object.create({
- isStarted: true
- })
- ]);
- expect(controller.moveToNextCommand()).to.be.false;
- });
- it('Command is not started', function () {
- controller.set('commands', [
- Em.Object.create({
- isStarted: false,
- name: 'command1'
- })
- ]);
- expect(controller.moveToNextCommand()).to.be.true;
- expect(controller.startCommand.calledWith(Em.Object.create({
- isStarted: false,
- name: 'command1'
- }))).to.be.true;
- });
- it('Next command provide as argument', function () {
- var nextCommand = Em.Object.create({
- isStarted: false,
- name: 'command2'
- });
- expect(controller.moveToNextCommand(nextCommand)).to.be.true;
- expect(controller.startCommand.calledWith(Em.Object.create({
- isStarted: false,
- name: 'command2'
- }))).to.be.true;
- });
- });
- describe('#setServiceTagNames()', function () {
- var testCases = [
- {
- title: 'configs is empty object',
- content: {
- secureService: {},
- configs: {}
- },
- result: undefined
- },
- {
- title: 'secureService.sites is null',
- content: {
- secureService: {
- sites: null
- },
- configs: {
- site1: {}
- }
- },
- result: undefined
- },
- {
- title: 'secureService.sites doesn\'t contain required config tag',
- content: {
- secureService: {
- sites: []
- },
- configs: {
- site1: {}
- }
- },
- result: undefined
- },
- {
- title: 'secureService.sites contains required config tag',
- content: {
- secureService: {
- sites: ['site1']
- },
- configs: {
- site1: {
- tag: 'tag1'
- }
- }
- },
- result: {
- siteName: 'site1',
- tagName: 'tag1',
- newTagName: null,
- configs: {}
- }
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- expect(controller.setServiceTagNames(test.content.secureService, test.content.configs)).to.eql(test.result);
- });
- });
- });
- });
|