123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- /**
- * 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('mixins/common/localStorage');
- require('controllers/wizard');
- require('controllers/main/admin/security/add/addSecurity_controller');
- require('models/cluster');
- require('models/service');
- describe('App.AddSecurityController', function () {
- var controller = App.AddSecurityController.create({
- currentStep: null
- });
- describe('#installedServices', function () {
- afterEach(function () {
- App.Service.find.restore();
- });
- it('No installed services', function () {
- sinon.stub(App.Service, 'find', function () {
- return [];
- });
- expect(controller.get('installedServices')).to.eql([]);
- });
- it('One service installed', function () {
- sinon.stub(App.Service, 'find', function () {
- return [Em.Object.create({serviceName: 'HDFS'})];
- });
- Em.propertyDidChange(controller, 'installedServices');
- expect(controller.get('installedServices')).to.eql(['HDFS']);
- });
- });
- describe('#secureServices', function () {
- afterEach(function () {
- App.get.restore();
- });
- it('App.isHadoop2Stack = false', function () {
- var result = [
- "GENERAL",
- "HDFS",
- "MAPREDUCE",
- "HIVE",
- "HBASE",
- "ZOOKEEPER",
- "OOZIE",
- "NAGIOS"
- ];
- sinon.stub(App, 'get', function () {
- return false;
- });
- Em.propertyDidChange(App, 'isHadoop2Stack');
- expect(controller.get('secureServices').mapProperty('serviceName')).to.eql(result);
- });
- it('App.isHadoop2Stack = true', function () {
- var result = [
- "GENERAL",
- "HDFS",
- "MAPREDUCE2",
- "YARN",
- "HIVE",
- "HBASE",
- "ZOOKEEPER",
- "OOZIE",
- "NAGIOS",
- "STORM",
- "FALCON",
- "KNOX"
- ];
- sinon.stub(App, 'get', function () {
- return true;
- });
- Em.propertyDidChange(App, 'isHadoop2Stack');
- expect(controller.get('secureServices').mapProperty('serviceName')).to.eql(result);
- });
- });
- describe('#loadAllPriorSteps()', function () {
- beforeEach(function () {
- sinon.stub(controller, 'loadServiceConfigs', Em.K);
- sinon.stub(controller, 'loadServices', Em.K);
- sinon.stub(controller, 'loadNnHaStatus', Em.K);
- });
- afterEach(function () {
- controller.loadServiceConfigs.restore();
- controller.loadServices.restore();
- controller.loadNnHaStatus.restore();
- });
- var commonSteps = ['4', '3', '2'];
- commonSteps.forEach(function (step) {
- it('Current step - ' + step, function () {
- controller.set('currentStep', step);
- controller.loadAllPriorSteps();
- expect(controller.loadServiceConfigs.calledOnce).to.be.true;
- expect(controller.loadServices.calledOnce).to.be.true;
- expect(controller.loadNnHaStatus.calledOnce).to.be.true;
- });
- });
- it('Current step - 1', function () {
- controller.set('currentStep', '1');
- controller.loadAllPriorSteps();
- expect(controller.loadServiceConfigs.called).to.be.false;
- expect(controller.loadServices.calledOnce).to.be.true;
- expect(controller.loadNnHaStatus.calledOnce).to.be.true;
- });
- });
- describe('#loadServices()', function () {
- it('No installed services', function () {
- controller.reopen({
- installedServices: [],
- secureServices: [
- {serviceName: 'GENERAL'}
- ]
- });
- controller.loadServices();
- expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
- });
- it('Installed service does not match the secure one', function () {
- controller.set('installedServices', ["HDFS"]);
- controller.loadServices();
- expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
- });
- it('Installed service matches the secure one', function () {
- controller.set('secureServices', [
- {serviceName: 'GENERAL'},
- {serviceName: 'HDFS'}
- ]);
- controller.loadServices();
- expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL', 'HDFS']);
- });
- });
- describe('#loadNnHaStatus()', function () {
- afterEach(function () {
- App.db.getIsNameNodeHa.restore();
- });
- it('NameNode HA is off', function () {
- sinon.stub(App.db, 'getIsNameNodeHa', function () {
- return false;
- });
- controller.loadNnHaStatus();
- expect(controller.get('content.isNnHa')).to.be.false;
- });
- it('NameNode HA is on', function () {
- sinon.stub(App.db, 'getIsNameNodeHa', function () {
- return true;
- });
- controller.loadNnHaStatus();
- expect(controller.get('content.isNnHa')).to.be.true;
- });
- });
- describe('#loadServiceConfigs()', function () {
- afterEach(function () {
- App.db.getSecureConfigProperties.restore();
- });
- it('SecureConfigProperties is empty', function () {
- sinon.stub(App.db, 'getSecureConfigProperties', function () {
- return [];
- });
- controller.loadServiceConfigs();
- expect(controller.get('content.serviceConfigProperties')).to.eql([]);
- });
- it('SecureConfigProperties has one config', function () {
- sinon.stub(App.db, 'getSecureConfigProperties', function () {
- return [{}];
- });
- controller.loadServiceConfigs();
- expect(controller.get('content.serviceConfigProperties')).to.eql([{}]);
- });
- });
- describe('#getConfigOverrides()', function () {
- var testCases = [
- {
- title: 'overrides is null',
- configProperty: Em.Object.create({overrides: null}),
- result: null
- },
- {
- title: 'overrides is empty',
- configProperty: Em.Object.create({overrides: []}),
- result: null
- },
- {
- title: 'overrides has one override',
- configProperty: Em.Object.create({
- overrides: [
- Em.Object.create({
- value: 'value1',
- selectedHostOptions: []
- })
- ]
- }),
- result: [{
- value: 'value1',
- hosts: []
- }]
- },
- {
- title: 'overrides has one override with hosts',
- configProperty: Em.Object.create({
- overrides: [
- Em.Object.create({
- value: 'value1',
- selectedHostOptions: ['host1']
- })
- ]
- }),
- result: [{
- value: 'value1',
- hosts: ['host1']
- }]
- }
- ];
- testCases.forEach(function(test){
- it(test.title, function () {
- expect(controller.getConfigOverrides(test.configProperty)).to.eql(test.result);
- });
- });
- });
- describe('#saveServiceConfigProperties()', function () {
- var testCases = [
- {
- title: 'stepConfigs is empty',
- stepController: Em.Object.create({
- stepConfigs: []
- }),
- result: []
- },
- {
- title: 'No configs in service',
- stepController: Em.Object.create({
- stepConfigs: [
- Em.Object.create({configs: []})
- ]
- }),
- result: []
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
- controller.saveServiceConfigProperties(test.stepController);
- expect(App.db.setSecureConfigProperties.calledWith(test.result)).to.be.true;
- expect(controller.get('content.serviceConfigProperties')).to.eql(test.result);
- App.db.setSecureConfigProperties.restore();
- });
- });
- it('Service has config', function () {
- var stepController = Em.Object.create({
- stepConfigs: [
- Em.Object.create({configs: [
- Em.Object.create({
- name: 'config1',
- value: 'value1'
- })
- ]})
- ]
- });
- sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
- controller.saveServiceConfigProperties(stepController);
- expect(App.db.setSecureConfigProperties.calledOnce).to.be.true;
- expect(controller.get('content.serviceConfigProperties').mapProperty('name')).to.eql(['config1']);
- App.db.setSecureConfigProperties.restore();
- });
- });
- });
|