123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- /**
- * 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/highAvailability_controller');
- require('models/host_component');
- require('models/host');
- require('utils/ajax/ajax');
- describe('App.MainAdminHighAvailabilityController', function () {
- var controller = App.MainAdminHighAvailabilityController.create();
- describe('#enableHighAvailability()', function () {
- var hostComponents = [];
- beforeEach(function () {
- sinon.stub(App.HostComponent, 'find', function(){
- return hostComponents;
- });
- sinon.spy(controller, "showErrorPopup");
- });
- afterEach(function () {
- controller.showErrorPopup.restore();
- App.HostComponent.find.restore();
- });
- it('Security enabled', function () {
- controller.set('securityEnabled', true);
- expect(controller.enableHighAvailability()).to.be.false;
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- });
- it('NAMENODE in INSTALLED state', function () {
- controller.set('securityEnabled', false);
- hostComponents = [
- Em.Object.create({
- componentName: 'NAMENODE',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- })
- ];
- sinon.stub(App.router, 'get', function(){
- return 3;
- });
- expect(controller.enableHighAvailability()).to.be.false;
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- App.router.get.restore();
- });
- it('Cluster has less than 3 ZOOKEPER_SERVER components', function () {
- hostComponents = [
- Em.Object.create({
- componentName: 'NAMENODE',
- workStatus: 'STARTED'
- })
- ];
- sinon.stub(App.router, 'get', function(){
- return 3;
- });
- expect(controller.enableHighAvailability()).to.be.false;
- expect(controller.showErrorPopup.called).to.be.true;
- App.router.get.restore();
- });
- it('total hosts number less than 3', function () {
- controller.set('securityEnabled', false);
- hostComponents = [
- Em.Object.create({
- componentName: 'NAMENODE',
- workStatus: 'STARTED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- })
- ];
- sinon.stub(App.router, 'get', function () {
- return 1;
- });
- expect(controller.enableHighAvailability()).to.be.false;
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- App.router.get.restore();
- });
- it('All checks passed', function () {
- controller.set('securityEnabled', false);
- hostComponents = [
- Em.Object.create({
- componentName: 'NAMENODE',
- workStatus: 'STARTED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- }),
- Em.Object.create({
- componentName: 'ZOOKEEPER_SERVER',
- workStatus: 'INSTALLED'
- })
- ];
- sinon.stub(App.router, 'get', function(){
- return 3;
- });
- sinon.spy(App.router, 'transitionTo');
- expect(controller.enableHighAvailability()).to.be.true;
- expect(App.router.transitionTo.calledWith('main.admin.enableHighAvailability')).to.be.true;
- expect(controller.showErrorPopup.calledOnce).to.be.false;
- App.router.transitionTo.restore();
- App.router.get.restore();
- });
- });
- describe('#setSecurityStatus()', function () {
- beforeEach(function () {
- sinon.stub(App.ajax, "send", Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it('testMode = true', function () {
- App.testEnableSecurity = false;
- App.testMode = true;
- controller.set('securityEnabled', false);
- controller.set('dataIsLoaded', false);
- controller.setSecurityStatus();
- expect(controller.get('securityEnabled')).to.be.true;
- expect(controller.get('dataIsLoaded')).to.be.true;
- expect(App.ajax.send.called).to.be.false;
- });
- it('testMode = false', function () {
- App.testMode = false;
- controller.set('securityEnabled', false);
- controller.set('dataIsLoaded', false);
- controller.setSecurityStatus();
- expect(controller.get('securityEnabled')).to.be.false;
- expect(controller.get('dataIsLoaded')).to.be.false;
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- describe('#getSecurityStatusFromServerSuccessCallback()', function () {
- beforeEach(function () {
- sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
- sinon.stub(controller, "showErrorPopup", Em.K);
- });
- afterEach(function () {
- controller.getServiceConfigsFromServer.restore();
- controller.showErrorPopup.restore();
- });
- it('desired_configs is empty', function () {
- var data = {
- Clusters: {
- desired_configs: {}
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- });
- it('desired_configs does not have "hadoop-env"', function () {
- var data = {
- Clusters: {
- desired_configs: {
- 'hdfs-site': {}
- }
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- });
- it('desired_configs has "hadoop-env"', function () {
- var data = {
- Clusters: {
- desired_configs: {
- 'hadoop-env': {
- tag: 1
- }
- }
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.get('tag')).to.equal(1);
- expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
- expect(controller.showErrorPopup.called).to.be.false;
- });
- });
- describe('#getSecurityStatusFromServerSuccessCallback()', function () {
- beforeEach(function () {
- sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
- sinon.stub(controller, "showErrorPopup", Em.K);
- });
- afterEach(function () {
- controller.getServiceConfigsFromServer.restore();
- controller.showErrorPopup.restore();
- });
- it('desired_configs is empty', function () {
- var data = {
- Clusters: {
- desired_configs: {}
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- });
- it('desired_configs does not have "hadoop-env"', function () {
- var data = {
- Clusters: {
- desired_configs: {
- 'hdfs-site': {}
- }
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.showErrorPopup.calledOnce).to.be.true;
- });
- it('desired_configs has "hadoop-env"', function () {
- var data = {
- Clusters: {
- desired_configs: {
- 'hadoop-env': {
- tag: 1
- }
- }
- }
- };
- controller.getSecurityStatusFromServerSuccessCallback(data);
- expect(controller.get('tag')).to.equal(1);
- expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
- expect(controller.showErrorPopup.called).to.be.false;
- });
- });
- describe('#joinMessage()', function () {
- it('message is empty', function () {
- var message = [];
- expect(controller.joinMessage(message)).to.be.empty;
- });
- it('message is array from two strings', function () {
- var message = ['yes', 'no'];
- expect(controller.joinMessage(message)).to.equal('yes<br/>no');
- });
- it('message is string', function () {
- var message = 'hello';
- expect(controller.joinMessage(message)).to.equal('<p>hello</p>');
- });
- });
- describe('#getServiceConfigsFromServer()', function () {
- it('configs present', function () {
- sinon.stub(App.router.get('configurationController'), 'getConfigsByTags', function () {
- return {
- done: function (callback) {
- callback([{tag: '1'}]);
- }
- }
- });
- sinon.stub(controller, 'isSecurityEnabled', function(){
- return true;
- });
- controller.set('tag', '1');
- controller.getServiceConfigsFromServer();
- expect(App.router.get('configurationController').getConfigsByTags.calledWith([
- {
- siteName: "hadoop-env",
- tagName: '1'
- }
- ])).to.be.true;
- expect(controller.isSecurityEnabled.calledOnce).to.be.true;
- expect(controller.get('dataIsLoaded')).to.be.true;
- expect(controller.get('securityEnabled')).to.be.true;
- App.router.get('configurationController').getConfigsByTags.restore();
- controller.isSecurityEnabled.restore();
- });
- });
- describe('#isSecurityEnabled()', function () {
- it('properties is null', function () {
- expect(controller.isSecurityEnabled(null)).to.be.false;
- });
- it('properties is empty object', function () {
- expect(controller.isSecurityEnabled({})).to.be.false;
- });
- it('security_enabled is false', function () {
- expect(controller.isSecurityEnabled({security_enabled: false})).to.be.false;
- });
- it('security_enabled is true', function () {
- expect(controller.isSecurityEnabled({security_enabled: true})).to.be.true;
- });
- it('security_enabled is "true"', function () {
- expect(controller.isSecurityEnabled({security_enabled: 'true'})).to.be.true;
- });
- });
- });
|