You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2014/05/12 19:24:12 UTC
[12/12] git commit: AMBARI-5737. Tests folder structure should be
equal to app folder structure. (onechiporenko)
AMBARI-5737. Tests folder structure should be equal to app folder structure. (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1d0fe34b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1d0fe34b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1d0fe34b
Branch: refs/heads/trunk
Commit: 1d0fe34b694d29a078377434dd3a322e9cf8ccac
Parents: b7dd314
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Mon May 12 20:16:49 2014 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Mon May 12 20:23:54 2014 +0300
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 22 +-
.../test/controllers/wizard/step0_test.js | 86 +
.../test/controllers/wizard/step10_test.js | 471 +++++
.../test/controllers/wizard/step2_test.js | 615 ++++++
.../test/controllers/wizard/step3_test.js | 1676 +++++++++++++++
.../test/controllers/wizard/step4_test.js | 484 +++++
.../test/controllers/wizard/step5_test.js | 1040 +++++++++
.../test/controllers/wizard/step6_test.js | 1356 ++++++++++++
.../test/controllers/wizard/step7_test.js | 1180 +++++++++++
.../test/controllers/wizard/step8_test.js | 1463 +++++++++++++
.../test/controllers/wizard/step9_test.js | 1979 ++++++++++++++++++
ambari-web/test/installer/step0_test.js | 86 -
ambari-web/test/installer/step10_test.js | 471 -----
ambari-web/test/installer/step2_test.js | 615 ------
ambari-web/test/installer/step3_test.js | 1676 ---------------
ambari-web/test/installer/step4_test.js | 484 -----
ambari-web/test/installer/step5_test.js | 1040 ---------
ambari-web/test/installer/step6_test.js | 1356 ------------
ambari-web/test/installer/step7_test.js | 1180 -----------
ambari-web/test/installer/step8_test.js | 1463 -------------
ambari-web/test/installer/step9_test.js | 1979 ------------------
21 files changed, 10361 insertions(+), 10361 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1d0fe34b/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 00642d1..2636f75 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -76,19 +76,19 @@ require('test/controllers/main/jobs/hive_job_details_controller_test');
require('test/controllers/main/service_test');
require('test/controllers/main/admin_test');
require('test/controllers/main/alerts_controller_test');
-require('test/controllers/wizard/stack_upgrade/step3_controller_test');
require('test/controllers/installer_test');
require('test/controllers/wizard_test');
-require('test/installer/step0_test');
-require('test/installer/step2_test');
-require('test/installer/step3_test');
-require('test/installer/step4_test');
-require('test/installer/step5_test');
-require('test/installer/step6_test');
-require('test/installer/step7_test');
-require('test/installer/step8_test');
-require('test/installer/step9_test');
-require('test/installer/step10_test');
+require('test/controllers/wizard/step0_test');
+require('test/controllers/wizard/step2_test');
+require('test/controllers/wizard/step3_test');
+require('test/controllers/wizard/step4_test');
+require('test/controllers/wizard/step5_test');
+require('test/controllers/wizard/step6_test');
+require('test/controllers/wizard/step7_test');
+require('test/controllers/wizard/step8_test');
+require('test/controllers/wizard/step9_test');
+require('test/controllers/wizard/step10_test');
+require('test/controllers/wizard/stack_upgrade/step3_controller_test');
require('test/login_test');
require('test/mappers/server_data_mapper_test');
require('test/mappers/hosts_mapper_test');
http://git-wip-us.apache.org/repos/asf/ambari/blob/1d0fe34b/ambari-web/test/controllers/wizard/step0_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step0_test.js b/ambari-web/test/controllers/wizard/step0_test.js
new file mode 100644
index 0000000..0c6a87a
--- /dev/null
+++ b/ambari-web/test/controllers/wizard/step0_test.js
@@ -0,0 +1,86 @@
+/**
+ * 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('models/cluster_states');
+require('controllers/wizard/step0_controller');
+var wizardStep0Controller;
+
+if (!App.router) {
+ App.router = Em.Object.create({});
+}
+App.router.set('send', Em.K);
+
+describe('App.WizardStep0Controller', function () {
+
+ beforeEach(function() {
+ wizardStep0Controller = App.WizardStep0Controller.create({content: {cluster: {}}});
+ sinon.stub(App.clusterStatus, 'set', Em.K);
+ sinon.spy(App.router, 'send');
+ });
+
+ afterEach(function() {
+ App.clusterStatus.set.restore();
+ App.router.send.restore();
+ });
+
+ describe('#invalidClusterName', function () {
+ it('should return true if no cluster name is present', function () {
+ wizardStep0Controller.set('hasSubmitted', true);
+ wizardStep0Controller.set('content', {'cluster':{'name':''}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ });
+ it('should return true if cluster name contains white spaces', function () {
+ wizardStep0Controller.set('hasSubmitted', true);
+ wizardStep0Controller.set('content', {'cluster':{'name':'the cluster'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ });
+ it('should return true if cluster name contains special chars', function () {
+ wizardStep0Controller.set('hasSubmitted', true);
+ wizardStep0Controller.set('content', {'cluster':{'name':'$cluster'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ })
+ });
+
+ describe('#loadStep', function() {
+ it('should clear step data', function() {
+ wizardStep0Controller.loadStep();
+ expect(wizardStep0Controller.get('hasSubmitted')).to.equal(false);
+ expect(wizardStep0Controller.get('clusterNameError')).to.equal('');
+ });
+ });
+
+ describe('#submit', function() {
+ it('if cluster name is valid should proceed', function() {
+ wizardStep0Controller.set('content.cluster.name', 'tdk');
+ wizardStep0Controller.submit();
+ expect(wizardStep0Controller.get('content.cluster.status')).to.equal('PENDING');
+ expect(wizardStep0Controller.get('content.cluster.isCompleted')).to.equal(false);
+ expect(App.router.send.calledWith('next')).to.equal(true);
+ expect(App.clusterStatus.set.calledWith('clusterName', 'tdk')).to.equal(true);
+ });
+
+ it('if cluster name isn\'t valid shouldn\'t proceed', function() {
+ wizardStep0Controller.set('content.cluster.name', '@@@@');
+ wizardStep0Controller.submit();
+ expect(App.router.send.called).to.equal(false);
+ expect(App.clusterStatus.set.called).to.equal(false);
+ });
+ });
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/1d0fe34b/ambari-web/test/controllers/wizard/step10_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step10_test.js b/ambari-web/test/controllers/wizard/step10_test.js
new file mode 100644
index 0000000..590d372
--- /dev/null
+++ b/ambari-web/test/controllers/wizard/step10_test.js
@@ -0,0 +1,471 @@
+/**
+ * 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/step10_controller');
+
+var controller;
+
+describe('App.WizardStep10Controller', function () {
+
+ beforeEach(function() {
+ controller = App.WizardStep10Controller.create();
+ controller.set('content', {cluster: {status: 'INSTALL COMPLETE'}});
+ });
+
+ afterEach(function() {
+ controller.clearStep();
+ });
+
+ describe('#clearStep', function() {
+ it('should clear clusterInfo', function() {
+ controller.get('clusterInfo').pushObject({});
+ controller.clearStep();
+ expect(controller.get('clusterInfo.length')).to.equal(0);
+ });
+ });
+
+ describe('#loadStep', function() {
+ beforeEach(function() {
+ sinon.spy(controller, 'clearStep');
+ sinon.stub(controller, 'loadRegisteredHosts', Em.K);
+ sinon.stub(controller, 'loadInstalledHosts', Em.K);
+ sinon.stub(controller, 'loadInstallTime', Em.K);
+ });
+ afterEach(function() {
+ controller.clearStep.restore();
+ controller.loadRegisteredHosts.restore();
+ controller.loadInstalledHosts.restore();
+ controller.loadInstallTime.restore();
+ });
+ it('should call clearStep', function() {
+ controller.loadStep();
+ expect(controller.clearStep.calledOnce).to.equal(true);
+ });
+ it('should call loadInstalledHosts', function() {
+ controller.loadStep();
+ expect(controller.loadInstalledHosts.calledOnce).to.equal(true);
+ });
+ it('should loadInstallTime if not installerController', function() {
+ controller.set('content.controllerName', 'addServiceController');
+ controller.loadStep();
+ expect(controller.loadInstallTime.calledOnce).to.equal(true);
+ });
+ var testsForLoadInstallTime = Em.A([
+ {
+ loadMasterComponents: true,
+ loadStartedServices: true,
+ e: true
+ },
+ {
+ loadMasterComponents: true,
+ loadStartedServices: false,
+ e: false
+ },
+ {
+ loadMasterComponents: false,
+ loadStartedServices: false,
+ e: false
+ },
+ {
+ loadMasterComponents: false,
+ loadStartedServices: false,
+ e: false
+ }
+ ]);
+ testsForLoadInstallTime.forEach(function(test) {
+ it('loadMasterComponents: ' + test.loadMasterComponents.toString() + ' loadStartedServices: ' + test.loadStartedServices.toString(), function() {
+ controller.set('content.controllerName', 'installerController');
+ sinon.stub(controller, 'loadMasterComponents', function() {return test.loadMasterComponents;});
+ sinon.stub(controller, 'loadStartedServices', function() {return test.loadStartedServices;});
+ controller.loadStep();
+ expect(controller.loadInstallTime.called).to.equal(test.e);
+ controller.loadMasterComponents.restore();
+ controller.loadStartedServices.restore();
+ });
+ });
+ });
+
+ describe('#loadInstalledHosts', function() {
+ var tests = Em.A([
+ {
+ hosts: {
+ 'h1': Em.Object.create({status: 'success', tasks: []}),
+ 'h2': Em.Object.create({status: 'success', tasks: []}),
+ 'h3': Em.Object.create({status: 'success', tasks: []})
+ },
+ m: 'all success',
+ e: Em.A([
+ {id: 1, l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({status: 'warning', tasks: []}),
+ 'h2': Em.Object.create({status: 'failed', tasks: []}),
+ 'h3': Em.Object.create({status: 'failed', tasks: []})
+ },
+ m: 'some failed, some warning',
+ e: Em.A([
+ {id: 2, l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({status: 'failed', tasks: []}),
+ 'h2': Em.Object.create({status: 'success', tasks: []}),
+ 'h3': Em.Object.create({status: 'warning', tasks: []})
+ },
+ m: 'sone failed, some success, some warning',
+ e: Em.A([
+ {id: 1, l: 1},
+ {id: 2, l: 2}
+ ])
+ }
+ ]);
+ tests.forEach(function(test) {
+ it(test.m, function() {
+ controller.set('content.hosts', test.hosts);
+ controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
+ controller.loadInstalledHosts();
+ test.e.forEach(function(ex) {
+ expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', ex.id).get('displayStatement').contains(ex.l)).to.equal(true);
+ });
+ })
+ });
+ var testsForFailedTasks = Em.A([
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'FAILED'}},
+ {Tasks: {status: 'FAILED'}}
+ ]
+ }),
+ 'h2': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'FAILED'}}
+ ]
+ }),
+ 'h3': Em.Object.create({status: 'failed', tasks: []})
+ },
+ m: 'only failed tasks',
+ e: Em.A([
+ {st: 'failed', l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ }),
+ 'h2': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ }),
+ 'h3': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ })
+ },
+ m: 'only timedout tasks',
+ e: Em.A([
+ {st: 'timedout', l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'failed',
+ tasks: []
+ }),
+ 'h2': Em.Object.create({
+ status: 'failed',
+ tasks: []
+ }),
+ 'h3': Em.Object.create({
+ status: 'failed',
+ tasks: [
+ {Tasks: {status: 'ABORTED'}},
+ {Tasks: {status: 'ABORTED'}},
+ {Tasks: {status: 'ABORTED'}}
+ ]
+ })
+ },
+ m: 'only aborted tasks',
+ e: Em.A([
+ {st: 'aborted', l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'FAILED'}},
+ {Tasks: {status: 'FAILED'}}
+ ]
+ }),
+ 'h2': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'FAILED'}}
+ ]
+ }),
+ 'h3': Em.Object.create({status: 'warning', tasks: []})
+ },
+ m: 'only failed tasks, warning hosts',
+ e: Em.A([
+ {st: 'failed', l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ }),
+ 'h2': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ }),
+ 'h3': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'TIMEDOUT'}}
+ ]
+ })
+ },
+ m: 'only timedout tasks, warning hosts',
+ e: Em.A([
+ {st: 'timedout', l: 3}
+ ])
+ },
+ {
+ hosts: {
+ 'h1': Em.Object.create({
+ status: 'warning',
+ tasks: []
+ }),
+ 'h2': Em.Object.create({
+ status: 'warning',
+ tasks: []
+ }),
+ 'h3': Em.Object.create({
+ status: 'warning',
+ tasks: [
+ {Tasks: {status: 'ABORTED'}},
+ {Tasks: {status: 'ABORTED'}},
+ {Tasks: {status: 'ABORTED'}}
+ ]
+ })
+ },
+ m: 'only aborted tasks, warning hosts',
+ e: Em.A([
+ {st: 'aborted', l: 3}
+ ])
+ }
+ ]);
+ testsForFailedTasks.forEach(function(test) {
+ it(test.m, function() {
+ controller.set('content.hosts', test.hosts);
+ controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
+ controller.loadInstalledHosts();
+ test.e.forEach(function(ex) {
+ expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').mapProperty('status', ex.st).length).to.equal(ex.l);
+ });
+ })
+ });
+ });
+
+ describe('#loadMasterComponent', function() {
+ var tests = Em.A([
+ {
+ component: Em.Object.create({hostName: 'h1'}),
+ e: 1
+ },
+ {
+ component: Em.Object.create({}),
+ e: 0
+ }
+ ]);
+
+ tests.forEach(function(test) {
+ it(test.component.get('hostName') ? 'Has hosNBame' : 'Doesn\'t have hostName', function() {
+ controller.clearStep();
+ controller.get('clusterInfo').pushObject(Em.Object.create({id: 2, status: []}));
+ controller.loadMasterComponent(test.component);
+ expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(test.e);
+ })
+ });
+ });
+
+ describe('#loadStartedServices', function() {
+ var tests = Em.A([
+ {
+ status: 'STARTED',
+ e: {
+ ids: [3, 4],
+ r: true
+ }
+ },
+ {
+ status: 'FAILED',
+ e: {
+ ids: [3],
+ r: false
+ }
+ }
+ ]);
+ tests.forEach(function(test) {
+ it(test.status, function() {
+ controller.set('content', {cluster: {status: test.status}});
+ var r = controller.loadStartedServices();
+ expect(r).to.equal(test.e.r);
+ expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e.ids);
+ });
+ });
+ });
+
+ describe('#loadInstallTime', function() {
+ var tests = Em.A([
+ {
+ installTime: 123,
+ e: [5]
+ },
+ {
+ installTime: null,
+ e: []
+ }
+ ]);
+
+ tests.forEach(function(test) {
+ it('Install time' + test.installTime ? ' available' : ' not available', function() {
+ controller.set('content', {cluster: {installTime: test.installTime}});
+ var r = controller.loadInstallTime();
+ expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e);
+ });
+ });
+ });
+
+ describe('#calculateInstallTime', function () {
+ it('from "9.21" to 9 minutes 12 seconds', function () {
+ expect(controller.calculateInstallTime('9.21')).to.eql({minutes: 9, seconds: 12});
+ });
+ it('from "0" to 0 minutes 0 seconds', function () {
+ expect(controller.calculateInstallTime('0')).to.eql({minutes: 0, seconds: 0});
+ });
+ it('from "10" to 10 minutes 0 seconds', function () {
+ expect(controller.calculateInstallTime('10')).to.eql({minutes: 10, seconds: 0});
+ });
+ it('from "0.5" to 0 minutes 30 seconds', function () {
+ expect(controller.calculateInstallTime('0.5')).to.eql({minutes: 0, seconds: 30});
+ });
+ });
+
+ describe('#loadMasterComponents', function() {
+
+ var components = Em.A(['NAMENODE','SECONDARY_NAMENODE','JOBTRACKER','HISTORYSERVER','RESOURCEMANAGER','HBASE_MASTER','HIVE_SERVER','OOZIE_SERVER','GANGLIA_SERVER','NAGIOS_SERVER']);
+
+ d3.range(1, components.length).forEach(function(i) {
+ d3.range(1, i).forEach(function(j) {
+ var c = components.slice(0, j);
+ it(c.join(', '), function() {
+ var m = c.map(function(component){return {component: component, displayName: component, hostName: 'h1'};});
+ controller.set('content.masterComponentHosts', m);
+ controller.loadMasterComponents();
+ expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(m.length);
+ });
+ });
+ });
+
+ });
+
+ describe('#isNagiosRestartRequired', function() {
+ Em.A([
+ {
+ controllerName: 'addServiceController',
+ isLoaded: true,
+ e: true
+ },
+ {
+ controllerName: 'installerController',
+ isLoaded: true,
+ e: false
+ },
+ {
+ controllerName: 'addServiceController',
+ isLoaded: false,
+ e: false
+ },
+ {
+ controllerName: 'installerController',
+ isLoaded: false,
+ e: false
+ }
+ ]).forEach(function (test) {
+ it(test.controllerName + ' Nagios loaded' + test.isLoaded.toString(), function () {
+ controller.set('content.controllerName', test.controllerName);
+ sinon.stub(App.Service, 'find', function() {
+ return Em.Object.create({
+ isLoaded: test.isLoaded
+ })
+ });
+ expect(controller.get('isNagiosRestartRequired')).to.equal(test.e);
+ App.Service.find.restore();
+ });
+ });
+ });
+
+ describe('#loadRegisteredHosts', function() {
+ it('should add object to clusterInfo', function() {
+ var masterComponentHosts = [{hostName: 'h1'}, {hostName: 'h2'}, {hostName: 'h3'}],
+ slaveComponentHosts = [{hosts: [{hostName: 'h1'}, {hostName: 'h4'}]}, {hosts: [{hostName: 'h2'}, {hostName: 'h5'}]}],
+ hosts = [{hostName: 'h6'}, {hostName: 'h3'}, {hostName: 'h7'}];
+ controller.set('content.masterComponentHosts', masterComponentHosts);
+ controller.set('content.slaveComponentHosts', slaveComponentHosts);
+ controller.set('clusterInfo', []);
+ sinon.stub(App.Host, 'find', function() {
+ return hosts;
+ });
+ var obj = controller.loadRegisteredHosts();
+ App.Host.find.restore();
+ expect(obj.id).to.equal(1);
+ expect(obj.color).to.equal('text-info');
+ expect(obj.displayStatement).to.equal(Em.I18n.t('installer.step10.hostsSummary').format(7));
+ expect(obj.status).to.eql([]);
+ expect(controller.get('clusterInfo.firstObject')).to.eql(obj);
+ });
+ });
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/1d0fe34b/ambari-web/test/controllers/wizard/step2_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step2_test.js b/ambari-web/test/controllers/wizard/step2_test.js
new file mode 100644
index 0000000..62a448c
--- /dev/null
+++ b/ambari-web/test/controllers/wizard/step2_test.js
@@ -0,0 +1,615 @@
+/**
+ * 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 Ember = require('ember');
+require('controllers/wizard/step2_controller');
+require('models/host');
+require('models/host_component');
+require('messages');
+var c;
+describe('App.WizardStep2Controller', function () {
+
+ beforeEach(function() {
+ c = App.WizardStep2Controller.create();
+ });
+
+ describe('#isInstaller', function() {
+ it('true if controllerName is installerController', function() {
+ var controller = App.WizardStep2Controller.create({content: {controllerName: 'installerController'}});
+ expect(controller.get('isInstaller')).to.equal(true);
+ });
+ it('false if controllerName isn\'t installerController', function() {
+ var controller = App.WizardStep2Controller.create({content: {controllerName: 'addServiceController'}});
+ expect(controller.get('isInstaller')).to.equal(false);
+ });
+ });
+
+ describe('#manualInstall', function() {
+ it('should be equal to content.installOptions.manualInstall', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
+ expect(controller.get('manualInstall')).to.equal(true);
+ controller.toggleProperty('content.installOptions.manualInstall');
+ expect(controller.get('manualInstall')).to.equal(false);
+ });
+ });
+
+ describe('#hostNames', function() {
+ it('should be equal to content.installOptions.hostNames', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {hostNames: ['1','2','3']}}});
+ expect(controller.get('hostNames')).to.eql(['1','2','3']);
+ controller.set('content.installOptions.hostNames', ['1', '2']);
+ expect(controller.get('hostNames')).to.eql(['1', '2']);
+ });
+ });
+
+ describe('#sshKey', function() {
+ it('should be equal to content.installOptions.sshKey', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {sshKey: '123'}}});
+ expect(controller.get('sshKey')).to.equal('123');
+ controller.set('content.installOptions.sshKey', '321');
+ expect(controller.get('sshKey')).to.equal('321');
+ });
+ });
+
+ describe('#sshUser', function() {
+ it('should be equal to content.installOptions.sshUser', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {sshUser: '123'}}});
+ expect(controller.get('sshUser')).to.equal('123');
+ controller.set('content.installOptions.sshUser', '321');
+ expect(controller.get('sshUser')).to.equal('321');
+ });
+ });
+
+ describe('#installType', function() {
+ it('should be manualDriven if manualInstall is selected', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
+ expect(controller.get('installType')).to.equal('manualDriven');
+ });
+ it('should be ambariDriven if manualInstall isn\'t selected', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: false}}});
+ expect(controller.get('installType')).to.equal('ambariDriven');
+ });
+ });
+
+ describe('#updateHostNameArr()', function () {
+
+ var controller = App.WizardStep2Controller.create({
+ hostNames: 'apache.ambari'
+ });
+ App.store.load(App.Host, {'host_name': 'apache.ambari', id: '1'});
+ controller.updateHostNameArr();
+
+ it('should push to hostNameArr only new host names', function(){
+ expect(controller.get('hostNameArr').length).to.equal(0);
+ });
+
+ it('should push to inputtedAgainHostNames already installed host names', function(){
+ expect(controller.get('inputtedAgainHostNames').length).to.equal(1);
+ })
+ });
+
+ describe('#isAllHostNamesValid()', function () {
+
+ var controller = App.WizardStep2Controller.create({
+ hostNames: ''
+ });
+
+ it('should return true if all host names are valid', function(){
+ controller.set('hostNames', 'amache.org ambari.com');
+ expect(controller.isAllHostNamesValid()).to.equal(true);
+ });
+
+ var tests = Em.A([
+ 'hostname',
+ '-hostname.com',
+ 'hostname-.com',
+ 'host_name.com',
+ '123.123.123.123',
+ 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname',
+ 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostname'
+ ]);
+ tests.forEach(function (test) {
+ it('should return false for invalid host names ' + test + ' ', function () {
+ controller.set('hostNames', test);
+ expect(controller.isAllHostNamesValid()).to.equal(false);
+ });
+ });
+ });
+
+ describe('#checkHostError()', function () {
+
+ var controller = App.WizardStep2Controller.create();
+
+ it('should set hostsError if hostNames is ""', function () {
+ controller.set('content', {'installOptions': {'hostNames': ''}});
+ controller.checkHostError();
+ expect(controller.get('hostsError').length).to.be.above(2);
+ });
+
+ it('should set hostsError to null if hostNames is valid', function () {
+ controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
+ controller.checkHostError();
+ expect(controller.get('hostsError')).to.equal(null);
+ })
+ });
+
+ describe('#checkHostAfterSubmitHandler()', function () {
+
+ it('should be called after changing hasSubmitted', function (done) {
+ var controller = App.WizardStep2Controller.create({
+ checkHostError: function () {
+ done();
+ }
+ });
+ controller.set('hasSubmitted', true);
+ });
+
+ it('should be called after changing hostNames', function (done) {
+ var controller = App.WizardStep2Controller.create({
+ hasSubmitted: true,
+ checkHostError: function () {
+ done();
+ }
+ });
+ controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
+ })
+ });
+
+ describe('#sshKeyError', function () {
+
+ var tests = Em.A([
+ {
+ manualInstall: false,
+ sshKey: '',
+ hasSubmitted: false,
+ e: null
+ },
+ {
+ manualInstall: true,
+ sshKey: '',
+ hasSubmitted: false,
+ e: null
+ },
+ {
+ manualInstall: true,
+ sshKey: 'nobody',
+ hasSubmitted: false,
+ e: null
+ },
+ {
+ manualInstall: false,
+ sshKey: 'nobody',
+ hasSubmitted: false,
+ e: null
+ },
+ {
+ manualInstall: false,
+ sshKey: '',
+ hasSubmitted: true,
+ e: null
+ },
+ {
+ manualInstall: true,
+ sshKey: '',
+ hasSubmitted: true,
+ e: null
+ },
+ {
+ manualInstall: true,
+ sshKey: 'nobody',
+ hasSubmitted: true,
+ e: null
+ },
+ {
+ manualInstall: false,
+ sshKey: 'nobody',
+ hasSubmitted: true,
+ e: null
+ }
+ ]);
+
+ tests.forEach(function(test) {
+ it(test.sshKey + ' ' + test.manualInstall.toString() + ' ' + test.hasSubmitted.toString(), function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshKey: test.sshKey}}});
+ if(Em.isNone(test.e)) {
+ expect(controller.get('sshKeyError')).to.equal(null);
+ }
+ else {
+ expect(controller.get('sshKeyError').length).to.be.above(2);
+ }
+ });
+ });
+ });
+
+ describe('#sshUserError', function () {
+
+ var tests = Em.A([
+ {
+ manualInstall: false,
+ sshUser: '',
+ e: ''
+ },
+ {
+ manualInstall: true,
+ sshUser: '',
+ e: null
+ },
+ {
+ manualInstall: true,
+ sshUser: 'nobody',
+ e: null
+ },
+ {
+ manualInstall: false,
+ sshUser: 'nobody',
+ e: null
+ }
+ ]);
+
+ tests.forEach(function(test) {
+ it('', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshUser: test.sshUser}}});
+ if(Em.isNone(test.e)) {
+ expect(controller.get('sshUserError')).to.equal(null);
+ }
+ else {
+ expect(controller.get('sshUserError').length).to.be.above(2);
+ }
+ });
+ });
+
+ });
+
+ describe('#getHostInfo()', function () {
+
+ it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNameArr: ['apache', 'ambari'],
+ installType: 'manualDriven'
+ });
+
+ var test = controller.getHostInfo();
+ expect(test).to.eql({
+ 'apache':{'name':'apache', 'installType': 'manualDriven', 'bootStatus': 'PENDING'},
+ 'ambari':{'name':'ambari', 'installType': 'manualDriven', 'bootStatus': 'PENDING'}
+ });
+ })
+ });
+
+ describe('#setSshKey()', function () {
+
+ it('should set content.installOptions.sshKey', function () {
+ var controller = App.WizardStep2Controller.create({
+ content: {'installOptions': {'sshKey': '111'}}
+ });
+ controller.setSshKey('222');
+ expect(controller.get('content.installOptions.sshKey')).to.equal('222');
+ })
+ });
+
+ describe('#evaluateStep()', function () {
+
+ it('should return false if isSubmitDisabled is true', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNames: 'apache.ambari'
+ });
+ controller.set('isSubmitDisabled', true);
+ expect(controller.evaluateStep()).to.equal(false);
+ });
+
+ it('should return false if hostsError is not empty', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNames: 'apache.ambari'
+ });
+ controller.set('hostsError', 'error');
+ expect(controller.evaluateStep()).to.equal(false);
+ });
+
+ it('should return false if sshKeyError is not empty', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNames: 'apache.ambari'
+ });
+ controller.set('sshKeyError', 'error');
+ expect(controller.evaluateStep()).to.equal(false);
+ });
+
+ it('should return false if hostNameArr is empty', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNames: ''
+ });
+ expect(controller.evaluateStep()).to.equal(false);
+ });
+
+ it('should return false if isPattern is false', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNames: 'apache.ambari',
+ isPattern: false
+ });
+ expect(controller.evaluateStep()).to.equal(false);
+ })
+ });
+
+ describe('#parseHostNamesAsPatternExpression()', function () {
+
+ it('should parse hosts from pattern expression to hostNameArr', function () {
+ var controller = App.WizardStep2Controller.create({
+ hostNameArr: ['host[001-011]']
+ });
+ controller.parseHostNamesAsPatternExpression();
+ var result = true;
+ var hosts = controller.get('hostNameArr');
+ for (var i = 1; i<12; i++) {
+ var extra = (i.toString().length == 1) ? 0 : '';
+ if (hosts[i-1] !== 'host0' + extra + i) {
+ result = false;
+ }
+ }
+ expect(result).to.equal(true);
+ })
+ });
+
+ describe('#proceedNext()', function () {
+
+ it('should call warningPopup if not isAllHostNamesValid and no warningConfirmed', function() {
+ c.reopen({
+ isAllHostNamesValid: function() {
+ return false;
+ },
+ warningPopup: Em.K
+ });
+ sinon.spy(c, 'warningPopup');
+ var r = c.proceedNext(false);
+ expect(r).to.equal(false);
+ expect(c.warningPopup.calledOnce).to.equal(true);
+ });
+
+ it('should call manualInstallPopup if manualInstall is true', function () {
+ c.reopen({
+ hostNames: '',
+ manualInstall: true,
+ manualInstallPopup: Em.K
+ });
+ sinon.spy(c, 'manualInstallPopup');
+ var r = c.proceedNext(true);
+ expect(r).to.equal(false);
+ expect(c.manualInstallPopup.calledOnce).to.equal(true);
+ });
+
+ it ('should save hosts and proceed next if skipBootstrap is true', function() {
+ sinon.stub(App, 'get', function(k) {
+ if ('skipBootstrap' === k) {
+ return true;
+ }
+ return Em.get(App, k);
+ });
+ sinon.stub(App.router, 'send', Em.K);
+ c.reopen({
+ hostNameArr: ['h1'],
+ isAllHostNamesValid: function() {return true;},
+ content: {
+ installOptions: {},
+ hosts: null
+ }
+ });
+ var r = c.proceedNext();
+ expect(r).to.equal(true);
+ expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
+ expect(App.router.send.calledWith('next')).to.equal(true);
+ App.get.restore();
+ App.router.send.restore();
+ });
+
+ it('should call setupBootStrap', function() {
+ sinon.stub(App, 'get', function(k) {
+ if ('skipBootstrap' === k) {
+ return false;
+ }
+ return Em.get(App, k);
+ });
+ c.reopen({
+ hostNameArr: ['h1'],
+ isAllHostNamesValid: function() {return true;},
+ content: {
+ installOptions: {},
+ hosts: null
+ }
+ });
+ sinon.stub(c, 'setupBootStrap', Em.K);
+ var r = c.proceedNext();
+ expect(r).to.equal(true);
+ expect(c.setupBootStrap.calledOnce).to.eql(true);
+ App.get.restore();
+ c.setupBootStrap.restore();
+ });
+
+ });
+
+ describe('#isSubmitDisabled', function () {
+
+ var controller = App.WizardStep2Controller.create({
+ hostsError: '',
+ sshKeyError: ''
+ });
+
+ it('should return value if hostsError is not empty', function () {
+ controller.set('hostsError', 'error');
+ expect(controller.get('isSubmitDisabled').length).to.above(0);
+ });
+
+ it('should return value if sshKeyError is not empty', function () {
+ controller.set('sshKeyError', 'error');
+ controller.set('hostsError', '');
+ expect(controller.get('isSubmitDisabled').length).to.above(0);
+ })
+ });
+
+ describe('#installedHostsPopup', function() {
+ beforeEach(function() {
+ sinon.spy(App.ModalPopup, 'show');
+ sinon.stub(c, 'proceedNext', Em.K);
+ });
+ afterEach(function() {
+ App.ModalPopup.show.restore();
+ c.proceedNext.restore();
+ });
+ it('should call App.ModalPopup.show', function() {
+ c.installedHostsPopup();
+ expect(App.ModalPopup.show.calledOnce).to.equal(true);
+ });
+ it('should proceed next on primary', function() {
+ c.installedHostsPopup().onPrimary();
+ expect(c.proceedNext.calledOnce).to.equal(true);
+ });
+ });
+
+ describe('#warningPopup', function() {
+ beforeEach(function() {
+ sinon.spy(App.ModalPopup, 'show');
+ sinon.stub(c, 'proceedNext', Em.K);
+ });
+ afterEach(function() {
+ App.ModalPopup.show.restore();
+ c.proceedNext.restore();
+
+ });
+ it('should call App.ModalPopup.show', function() {
+ c.warningPopup();
+ expect(App.ModalPopup.show.calledOnce).to.equal(true);
+ });
+ it('should proceed next on primary', function() {
+ c.warningPopup().onPrimary();
+ expect(c.proceedNext.calledWith(true)).to.equal(true);
+ });
+ });
+
+ describe('#hostNamePatternPopup', function() {
+ beforeEach(function() {
+ sinon.spy(App.ModalPopup, 'show');
+ sinon.stub(c, 'proceedNext', Em.K);
+ });
+ afterEach(function() {
+ App.ModalPopup.show.restore();
+ c.proceedNext.restore();
+ });
+ it('should call App.ModalPopup.show', function() {
+ c.hostNamePatternPopup();
+ expect(App.ModalPopup.show.calledOnce).to.equal(true);
+ });
+ it('should proceed next on primary', function() {
+ c.hostNamePatternPopup().onPrimary();
+ expect(c.proceedNext.calledOnce).to.equal(true);
+ });
+ });
+
+ describe('#manualInstallPopup', function() {
+ beforeEach(function() {
+ sinon.spy(App.ModalPopup, 'show');
+ sinon.stub(App.router, 'send', Em.K);
+ sinon.stub(c, 'saveHosts', Em.K);
+ });
+ afterEach(function() {
+ App.ModalPopup.show.restore();
+ App.router.send.restore();
+ c.saveHosts.restore();
+ });
+ it('should call App.ModalPopup.show', function() {
+ c.manualInstallPopup();
+ expect(App.ModalPopup.show.calledOnce).to.equal(true);
+ });
+ it('should save hosts and go next on primary', function() {
+ c.manualInstallPopup().onPrimary();
+ expect(c.saveHosts.calledOnce).to.equal(true);
+ expect(App.router.send.calledWith('next')).to.equal(true);
+ });
+ });
+
+ describe('#manualInstallWarningPopup', function() {
+ beforeEach(function() {
+ sinon.spy(App.ModalPopup, 'show');
+ });
+ afterEach(function() {
+ App.ModalPopup.show.restore();
+ });
+ it('should call App.ModalPopup.show if content.installOptions.useSsh is false', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: false}}});
+ controller.manualInstallWarningPopup();
+ expect(App.ModalPopup.show.calledOnce).to.equal(true);
+ });
+ it('shouldn\'t call App.ModalPopup.show if content.installOptions.useSsh is true', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: true}}});
+ controller.manualInstallWarningPopup();
+ expect(App.ModalPopup.show.called).to.equal(false);
+ });
+ });
+
+ describe('#setAmbariJavaHome', function() {
+ beforeEach(function() {
+ sinon.spy($, 'ajax');
+ });
+ afterEach(function() {
+ $.ajax.restore();
+ });
+ it('should do ajax-request', function() {
+ var controller = App.WizardStep2Controller.create({onGetAmbariJavaHomeSuccess: Em.K, onGetAmbariJavaHomeError: Em.K});
+ controller.setAmbariJavaHome();
+ expect($.ajax.calledOnce).to.equal(true);
+ });
+ });
+
+ describe('#onGetAmbariJavaHomeSuccess', function() {
+ it('should set java.home value receiced from server', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
+ var test = {RootServiceComponents: {properties: {'java.home': '/root'}}};
+ controller.onGetAmbariJavaHomeSuccess(test);
+ expect(controller.content.installOptions.javaHome).to.equal('/root');
+ });
+ });
+
+ describe('#onGetAmbariJavaHomeError', function() {
+ it('should set default java.home value', function() {
+ var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
+ controller.onGetAmbariJavaHomeError();
+ expect(controller.content.installOptions.javaHome).to.equal(App.get('defaultJavaHome'));
+ });
+ });
+
+ describe('#saveHosts', function() {
+ beforeEach(function() {
+ sinon.stub(c, 'setAmbariJavaHome', Em.K);
+ c.reopen({
+ hostNameArr: ['h1'],
+ content: {
+ hosts: null
+ }
+ });
+ });
+ afterEach(function() {
+ c.setAmbariJavaHome.restore();
+ });
+ it('should call setAmbariJavaHome', function() {
+ c.saveHosts();
+ expect(c.setAmbariJavaHome.calledOnce).to.equal(true);
+ });
+ it('should set content.hosts', function() {
+ c.saveHosts();
+ expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
+ });
+ });
+
+});