123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- /**
- * 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');
- var c;
- describe('App.ManageConfigGroupsController', function() {
- var controller = App.ManageConfigGroupsController.create({});
- beforeEach(function() {
- c = App.ManageConfigGroupsController.create({});
- });
- var manageConfigGroupsController = App.ManageConfigGroupsController.create({});
- describe('#addConfigGroup', function() {
- beforeEach(function() {
- manageConfigGroupsController.addConfigGroup();
- });
- describe("#validate", function() {
- it("should display no warning if user inputs valid characters into group name", function() {
- manageConfigGroupsController.addGroupPopup.set('configGroupName', 'hello');
- expect(manageConfigGroupsController.addGroupPopup.warningMessage).to.be.empty;
- });
- it("should display warning if user inputs invalid characters into group name", function() {
- manageConfigGroupsController.addGroupPopup.set('configGroupName', '/{"!@#$%');
- expect(manageConfigGroupsController.addGroupPopup.warningMessage).to.equal('Invalid Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.');
- });
- });
- });
- describe('#renameConfigGroup', function() {
- beforeEach(function() {
- var configGroup = Ember.Object.create ({
- name: 'name',
- description: 'description'
- });
- manageConfigGroupsController.set('selectedConfigGroup', configGroup);
- manageConfigGroupsController.renameConfigGroup();
- });
- describe("#validate", function() {
- it("should display no warning if user inputs valid characters into group name", function() {
- manageConfigGroupsController.renameGroupPopup.set('configGroupName', 'hello');
- expect(manageConfigGroupsController.renameGroupPopup.warningMessage).to.be.empty;
- });
- it("should display warning if user inputs invalid characters into group name", function() {
- manageConfigGroupsController.renameGroupPopup.set('configGroupName', '/{"!@#$%');
- expect(manageConfigGroupsController.renameGroupPopup.warningMessage).to.equal('Invalid Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.');
- });
- });
- });
- describe('#addHostsCallback', function() {
- beforeEach(function() {
- c.reopen({
- selectedConfigGroup: Em.Object.create({
- hosts: ['h1'],
- parentConfigGroup: Em.Object.create({
- hosts: ['h2', 'h3']
- })
- })
- });
- });
- it('should set hosts to selectedConfigGroup and remove them form default group', function () {
- c.addHostsCallback(['h2', 'h3']);
- expect(c.get('selectedConfigGroup.hosts')).to.include.members(['h1','h2','h3']);
- expect(c.get('selectedConfigGroup.parentConfigGroup.hosts').toArray()).to.be.empty;
- });
- });
- describe('#isHostsModified', function () {
- Em.A([
- {
- o: {
- toClearHosts: [],
- toDelete: [],
- toSetHosts: [],
- toCreate: []
- },
- e: false
- },
- {
- o: {
- toClearHosts: [{}],
- toDelete: [],
- toSetHosts: [],
- toCreate: []
- },
- e: true
- },
- {
- o: {
- toClearHosts: [],
- toDelete: [{}],
- toSetHosts: [],
- toCreate: []
- },
- e: true
- },
- {
- o: {
- toClearHosts: [],
- toDelete: [],
- toSetHosts: [{}],
- toCreate: []
- },
- e: true
- },
- {
- o: {
- toClearHosts: [],
- toDelete: [],
- toSetHosts: [],
- toCreate: [{}]
- },
- e: true
- }
- ]).forEach(function (test, index) {
- it('test #' + index, function () {
- c.reopen({
- isLoaded: true,
- hostsModifiedConfigGroups: test.o
- });
- expect(c.get('isHostsModified')).to.equal(test.e);
- });
- });
- });
- describe('#deleteConfigGroup', function () {
- beforeEach(function() {
- var defaultGroup = Em.Object.create({
- hosts: ['h2', 'h3'],
- isDefault: true
- });
- var selectedGroup = Em.Object.create({
- hosts: ['h1'],
- parentConfigGroup: defaultGroup
- });
- c.reopen({
- configGroups: [defaultGroup, selectedGroup],
- selectedConfigGroup: selectedGroup
- });
- });
- it('after deleting some config group, Default should be selected', function () {
- c.deleteConfigGroup();
- expect(c.get('configGroups.length')).to.equal(1);
- expect(c.get('selectedConfigGroup.hosts')).to.include.members(['h1','h2','h3']);
- expect(c.get('selectedConfigGroup.isDefault')).to.be.true;
- });
- });
- describe("#manageConfigurationGroups", function () {
- var service = Em.Object.create({});
- manageConfigGroupsController.set('hostsModifiedConfigGroups', {});
- describe("#controller passed", function () {
- controller = Em.Object.create({
- content: Em.Object.create()
- });
- var popup = manageConfigGroupsController.manageConfigurationGroups(controller, service);
- describe("#onPrimary()", function () {
- beforeEach(function () {
- sinon.stub(popup, 'onPrimaryWizard', Em.K);
- });
- afterEach(function () {
- popup.onPrimaryWizard.restore();
- });
- it("onPrimaryWizard is called", function () {
- popup.onPrimary();
- expect(popup.onPrimaryWizard.calledOnce).to.be.true;
- });
- });
- describe("#onPrimaryWizard()", function () {
- var ctrl = Em.Object.create({
- selectedService: Em.Object.create({
- selected: false
- }),
- selectedServiceObserver: Em.K,
- setGroupsToDelete: Em.K
- });
- beforeEach(function () {
- sinon.spy(ctrl, 'selectedServiceObserver');
- sinon.spy(ctrl, 'setGroupsToDelete');
- sinon.stub(manageConfigGroupsController, 'persistConfigGroups', Em.K);
- sinon.stub(popup, 'updateConfigGroupOnServicePage', Em.K);
- sinon.stub(popup, 'hide', Em.K);
- });
- afterEach(function () {
- ctrl.setGroupsToDelete.restore();
- ctrl.selectedServiceObserver.restore();
- manageConfigGroupsController.persistConfigGroups.restore();
- popup.updateConfigGroupOnServicePage.restore();
- popup.hide.restore();
- });
- describe("groups deleted on 7th step", function () {
- beforeEach(function () {
- ctrl.set('name', 'wizardStep7Controller');
- popup.onPrimaryWizard(ctrl, {toDelete: [1]});
- });
- it('selectedServiceObserver is called once', function () {
- expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
- });
- it('setGroupsToDelete is called with [1]', function () {
- expect(ctrl.setGroupsToDelete.calledWith([1])).to.be.true;
- });
- it('persistConfigGroups is called once', function () {
- expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
- });
- it('updateConfigGroupOnServicePage is called once', function () {
- expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
- });
- it('hide is called once', function () {
- expect(popup.hide.calledOnce).to.be.true;
- });
- });
- describe("wizard not on 7th step", function () {
- beforeEach(function () {
- ctrl.set('name', '');
- popup.onPrimaryWizard(ctrl, {});
- });
- it('selectedServiceObserver is called once', function () {
- expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
- });
- it('setGroupsToDelete is not called', function () {
- expect(ctrl.setGroupsToDelete.called).to.be.false;
- });
- it('persistConfigGroups is not called', function () {
- expect(manageConfigGroupsController.persistConfigGroups.called).to.be.false;
- });
- it('updateConfigGroupOnServicePage is not called', function () {
- expect(popup.updateConfigGroupOnServicePage.called).to.be.false;
- });
- it('hide is called once', function () {
- expect(popup.hide.calledOnce).to.be.true;
- });
- });
- describe("wizard on 7th step, service selected", function () {
- beforeEach(function () {
- ctrl.set('name', 'wizardStep7Controller');
- ctrl.set('selectedService.selected', true);
- popup.onPrimaryWizard(ctrl, {toDelete: [1]});
- });
- it('selectedServiceObserver is called once', function () {
- expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
- });
- it('setGroupsToDelete is not called', function () {
- expect(ctrl.setGroupsToDelete.called).to.be.false;
- });
- it('persistConfigGroups is called once', function () {
- expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
- });
- it('updateConfigGroupOnServicePage is called once', function () {
- expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
- });
- it('hide is called once', function () {
- expect(popup.hide.calledOnce).to.be.true;
- });
- });
- describe("wizard on 7th step, no groups to delete", function () {
- beforeEach(function () {
- ctrl.set('name', 'wizardStep7Controller');
- ctrl.set('selectedService.selected', false);
- popup.onPrimaryWizard(ctrl, {toDelete: []});
- });
- it('selectedServiceObserver is called once', function () {
- expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
- });
- it('setGroupsToDelete is not called', function () {
- expect(ctrl.setGroupsToDelete.called).to.be.false;
- });
- it('persistConfigGroups is called once', function () {
- expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
- });
- it('updateConfigGroupOnServicePage is called once', function () {
- expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
- });
- it('hide is called once', function () {
- expect(popup.hide.calledOnce).to.be.true;
- });
- });
- });
- });
- describe("#controller not passed", function () {
- var popup = manageConfigGroupsController.manageConfigurationGroups(null, service);
- describe("#onPrimary()", function () {
- beforeEach(function () {
- sinon.stub(popup, 'runClearCGQueue').returns({
- done: function (callback) {
- callback();
- }
- });
- sinon.stub(popup, 'runModifyCGQueue').returns({
- done: function (callback) {
- callback();
- }
- });
- sinon.stub(popup, 'runCreateCGQueue').returns({
- done: function (callback) {
- callback();
- }
- });
- sinon.stub(popup, 'updateConfigGroupOnServicePage', Em.K);
- sinon.stub(popup, 'hide', Em.K);
- manageConfigGroupsController.set('hostsModifiedConfigGroups', {toCreate: []});
- popup.onPrimary();
- });
- afterEach(function () {
- popup.runCreateCGQueue.restore();
- popup.runModifyCGQueue.restore();
- popup.runClearCGQueue.restore();
- popup.updateConfigGroupOnServicePage.restore();
- popup.hide.restore();
- });
- it("runClearCGQueue is called", function () {
- expect(popup.runClearCGQueue.calledOnce).to.be.true;
- });
- it("runModifyCGQueue is called", function () {
- expect(popup.runModifyCGQueue.calledOnce).to.be.true;
- });
- it("runCreateCGQueue is called", function () {
- expect(popup.runCreateCGQueue.calledOnce).to.be.true;
- });
- it("updateConfigGroupOnServicePage is called", function () {
- expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
- });
- it("hide is called", function () {
- expect(popup.hide.calledOnce).to.be.true;
- });
- });
- describe("#runClearCGQueue()", function () {
- beforeEach(function () {
- sinon.stub(manageConfigGroupsController, 'updateConfigurationGroup', Em.K);
- sinon.stub(manageConfigGroupsController, 'deleteConfigurationGroup', Em.K);
- popup.runClearCGQueue(Em.K, {
- initialGroups: [],
- toClearHosts: [Em.Object.create()],
- toDelete: [1]
- });
- });
- afterEach(function () {
- manageConfigGroupsController.updateConfigurationGroup.restore();
- manageConfigGroupsController.deleteConfigurationGroup.restore();
- });
- it("updateConfigurationGroup is called once", function () {
- expect(manageConfigGroupsController.updateConfigurationGroup.calledOnce).to.be.true;
- });
- it("deleteConfigurationGroup is called once", function () {
- expect(manageConfigGroupsController.deleteConfigurationGroup.calledOnce).to.be.true;
- });
- });
- describe("#runModifyCGQueue()", function () {
- beforeEach(function () {
- sinon.stub(manageConfigGroupsController, 'updateConfigurationGroup', Em.K);
- });
- afterEach(function () {
- manageConfigGroupsController.updateConfigurationGroup.restore();
- });
- it("updateConfigurationGroup is called once", function () {
- popup.runModifyCGQueue(Em.K, {toSetHosts: [1]});
- expect(manageConfigGroupsController.updateConfigurationGroup.calledOnce).to.be.true;
- });
- });
- describe("#runCreateCGQueue()", function () {
- beforeEach(function () {
- sinon.stub(manageConfigGroupsController, 'postNewConfigurationGroup', Em.K);
- });
- afterEach(function () {
- manageConfigGroupsController.postNewConfigurationGroup.restore();
- });
- it("postNewConfigurationGroup is called once", function () {
- popup.runCreateCGQueue(Em.K, {toCreate: [1]});
- expect(manageConfigGroupsController.postNewConfigurationGroup.calledOnce).to.be.true;
- });
- });
- });
- });
- describe('#_onLoadPropertiesSuccess', function () {
- var data = {
- items: [
- {
- type: 'type1',
- tag: 'tag1',
- properties: {
- prop1: 'val1',
- prop2: 'val2'
- }
- },
- {
- type: 'type1',
- tag: 'tag2',
- properties: {
- prop3: 'val3'
- }
- },
- {
- type: 'type2',
- tag: 'tag1',
- properties: {
- prop4: 'val4'
- }
- }
- ]
- };
- var params = {
- typeTagToGroupMap: {
- 'type1///tag1': 'group1',
- 'type1///tag2': 'group2',
- 'type2///tag1': 'group3'
- }
- };
- var configGroups = [
- Em.Object.create({
- name: 'group1',
- properties: []
- }),
- Em.Object.create({
- name: 'group2',
- properties: []
- }),
- Em.Object.create({
- name: 'group3',
- properties: []
- }),
- Em.Object.create({
- name: 'group4',
- properties: []
- })
- ];
- beforeEach(function () {
- sinon.stub(c, 'resortConfigGroup', Em.K);
- });
- afterEach(function () {
- c.resortConfigGroup.restore();
- });
- it('should set properties to config groups', function () {
- c.set('configGroups', configGroups);
- c._onLoadPropertiesSuccess(data, null, params);
- expect(JSON.stringify(c.get('configGroups'))).to.equal(JSON.stringify([
- Em.Object.create({
- properties: [
- {
- name: 'prop1',
- value: 'val1',
- type: 'type1'
- },
- {
- name: 'prop2',
- value: 'val2',
- type: 'type1'
- }
- ],
- name: 'group1'
- }),
- Em.Object.create({
- properties: [
- {
- name: 'prop3',
- value: 'val3',
- type: 'type1'
- }
- ],
- name: 'group2'
- }),
- Em.Object.create({
- properties: [
- {
- name: 'prop4',
- value: 'val4',
- type: 'type2'
- }
- ],
- name: 'group3'
- }),
- Em.Object.create({
- properties: [],
- name: 'group4'
- })
- ]));
- });
- });
- describe('#componentsForFilter', function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find', function () {
- return [
- Em.Object.create({
- serviceName: 'HDFS'
- }),
- Em.Object.create({
- serviceName: 'noHDFS'
- }),
- Em.Object.create({
- serviceName: 'HDFS'
- })
- ];
- });
- c.set('serviceName', 'HDFS');
- });
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- });
- it('should map components for current service', function () {
- expect(c.get('componentsForFilter')).to.have.property('length').equal(2);
- });
- it('no one is selected', function () {
- expect(c.get('componentsForFilter').mapProperty('selected')).to.be.eql([false, false]);
- });
- });
- });
|