http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main/service/reassign/step4_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/reassign/step4_controller_test.js b/ambari-web/test/controllers/main/service/reassign/step4_controller_test.js index 3b37770..19d9201 100644 --- a/ambari-web/test/controllers/main/service/reassign/step4_controller_test.js +++ b/ambari-web/test/controllers/main/service/reassign/step4_controller_test.js @@ -130,13 +130,21 @@ describe('App.ReassignMasterWizardStep4Controller', function () { App.router.get.restore(); }); - it('tests database connection', function() { - sinon.stub(controller, 'prepareDBCheckAction', Em.K); + describe('tests database connection', function() { - controller.testDBConnection(); - expect(controller.prepareDBCheckAction.calledOnce).to.be.true; + beforeEach(function () { + sinon.stub(controller, 'prepareDBCheckAction', Em.K); + }); + + afterEach(function () { + controller.prepareDBCheckAction.restore(); + }); + + it('prepareDBCheckAction is called once', function() { + controller.testDBConnection(); + expect(controller.prepareDBCheckAction.calledOnce).to.be.true; + }); - controller.prepareDBCheckAction.restore(); }); it('tests prepareDBCheckAction', function() { @@ -770,36 +778,42 @@ describe('App.ReassignMasterWizardStep4Controller', function () { describe('#setSecureConfigs()', function () { + beforeEach(function () { + this.stub = sinon.stub(App, 'get'); + }); + afterEach(function () { Em.tryInvoke(App.get, 'restore'); }); it('undefined component and security disabled', function () { var secureConfigs = []; - sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(false); + this.stub.withArgs('isKerberosEnabled').returns(false); controller.set('secureConfigsMap', []); expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false; expect(secureConfigs).to.eql([]); }); + it('component exist and security disabled', function () { var secureConfigs = []; - sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(false); + this.stub.withArgs('isKerberosEnabled').returns(false); controller.set('secureConfigsMap', [{ componentName: 'COMP1' }]); expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false; expect(secureConfigs).to.eql([]); }); + it('undefined component and security enabled', function () { var secureConfigs = []; - sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(true); + this.stub.withArgs('isKerberosEnabled').returns(true); controller.set('secureConfigsMap', []); expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false; expect(secureConfigs).to.eql([]); }); it('component exist and security enabled', function () { var secureConfigs = []; - sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(true); + this.stub.withArgs('isKerberosEnabled').returns(true); var configs = {'s1': { 'k1': 'kValue', 'p1': 'pValue'
http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main/service/reassign_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/reassign_controller_test.js b/ambari-web/test/controllers/main/service/reassign_controller_test.js index 48a6dec..ed9a861 100644 --- a/ambari-web/test/controllers/main/service/reassign_controller_test.js +++ b/ambari-web/test/controllers/main/service/reassign_controller_test.js @@ -101,6 +101,7 @@ describe('App.ReassignMasterController', function () { beforeEach(function () { sinon.stub(App.db, 'setMasterComponentHosts', Em.K); sinon.stub(reassignMasterController, 'setDBProperty', Em.K); + reassignMasterController.saveMasterComponentHosts(stepController); }); afterEach(function () { @@ -108,12 +109,23 @@ describe('App.ReassignMasterController', function () { reassignMasterController.setDBProperty.restore(); }); - it('should save master component hosts', function () { - reassignMasterController.saveMasterComponentHosts(stepController); + it('setMasterComponentHosts is called once', function () { expect(App.db.setMasterComponentHosts.calledOnce).to.be.true; + }); + + it('setDBProperty is called once', function () { expect(reassignMasterController.setDBProperty.calledOnce).to.be.true; + }); + + it('setMasterComponentHosts is called with valid arguments', function () { expect(App.db.setMasterComponentHosts.calledWith(masterComponentHosts)).to.be.true; + }); + + it('setDBProperty is called with valid arguments', function () { expect(reassignMasterController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true; + }); + + it('masterComponentHosts are equal to ' + JSON.stringify(masterComponentHosts), function () { expect(reassignMasterController.get('content.masterComponentHosts')).to.eql(masterComponentHosts); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js b/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js index 3178ef5..e860660 100644 --- a/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js +++ b/ambari-web/test/controllers/main/service/widgets/create/step2_controller_test.js @@ -282,115 +282,245 @@ describe('App.WidgetWizardStep2Controller', function () { }); describe("#initWidgetData()", function () { - it("new data", function () { - controller.set('expressions', []); - controller.set('dataSets', []); - controller.get('content').setProperties({ - widgetProperties: {a: 1}, - widgetValues: [1], - widgetMetrics: [2] + + describe("new data", function () { + + beforeEach(function () { + controller.set('expressions', []); + controller.set('dataSets', []); + controller.get('content').setProperties({ + widgetProperties: {a: 1}, + widgetValues: [1], + widgetMetrics: [2] + }); + + controller.initWidgetData(); + }); + + it('widgetProperties is {a: 1}', function () { + expect(controller.get('widgetProperties')).to.eql({a: 1}); + }); + + it('widgetValues is []', function () { + expect(controller.get('widgetValues')).to.eql([]); + }); + + it('widgetMetrics is []', function () { + expect(controller.get('widgetMetrics')).to.eql([]); + }); + + it('expressions is not empty', function () { + expect(controller.get('expressions')).to.not.be.empty; }); - controller.initWidgetData(); + it('dataSets is not empty', function () { + expect(controller.get('dataSets')).to.not.be.empty; + }); - expect(controller.get('widgetProperties')).to.eql({a: 1}); - expect(controller.get('widgetValues')).to.eql([]); - expect(controller.get('widgetMetrics')).to.eql([]); - expect(controller.get('expressions')).to.not.be.empty; - expect(controller.get('dataSets')).to.not.be.empty; }); - it("previously edited", function () { - controller.set('expressions', [{}]); - controller.set('dataSets', [{}]); - controller.get('content').setProperties({ - widgetProperties: {a: 1}, - widgetValues: [1], - widgetMetrics: [2] + + describe("previously edited", function () { + + beforeEach(function () { + controller.set('expressions', [{}]); + controller.set('dataSets', [{}]); + controller.get('content').setProperties({ + widgetProperties: {a: 1}, + widgetValues: [1], + widgetMetrics: [2] + }); + + controller.initWidgetData(); }); - controller.initWidgetData(); + it('widgetProperties is {a: 1}', function () { + expect(controller.get('widgetProperties')).to.eql({a: 1}); + }); + it('widgetValues is [1]', function () { + expect(controller.get('widgetValues')).to.eql([1]); + }); + it('widgetMetrics is [2]', function () { + expect(controller.get('widgetMetrics')).to.eql([2]); + }); + it('expressions is not empty', function () { + expect(controller.get('expressions')).to.not.be.empty; + }); + it('dataSets is not empty', function () { + expect(controller.get('dataSets')).to.not.be.empty; + }); - expect(controller.get('widgetProperties')).to.eql({a: 1}); - expect(controller.get('widgetValues')).to.eql([1]); - expect(controller.get('widgetMetrics')).to.eql([2]); - expect(controller.get('expressions')).to.not.be.empty; - expect(controller.get('dataSets')).to.not.be.empty; }); }); describe("#updateExpressions()", function () { + beforeEach(function () { sinon.stub(controller, 'parseExpression').returns({values: [1], metrics: [1]}); sinon.stub(controller, 'parseTemplateExpression').returns({values: [1], metrics: [1]}); sinon.stub(controller, 'parseGraphDataset').returns({values: [1], metrics: [1]}); }); + afterEach(function () { controller.parseExpression.restore(); controller.parseTemplateExpression.restore(); controller.parseGraphDataset.restore(); }); - it("empty expressions", function () { - controller.set('expressions', []); - controller.updateExpressions(); - expect(controller.parseExpression.called).to.be.false; - expect(controller.parseTemplateExpression.called).to.be.false; - expect(controller.parseGraphDataset.called).to.be.false; - expect(controller.get('widgetValues')).to.be.empty; - expect(controller.get('widgetMetrics')).to.be.empty; + + describe("empty expressions", function () { + + beforeEach(function () { + controller.set('expressions', []); + controller.updateExpressions(); + }); + + it('parseExpression is not called', function () { + expect(controller.parseExpression.called).to.be.false; + }); + it('parseTemplateExpression is not called', function () { + expect(controller.parseTemplateExpression.called).to.be.false; + }); + it('parseGraphDataset is not called', function () { + expect(controller.parseGraphDataset.called).to.be.false; + }); + it('widgetValues is empty', function () { + expect(controller.get('widgetValues')).to.be.empty; + }); + it('widgetMetrics is empty', function () { + expect(controller.get('widgetMetrics')).to.be.empty; + }); }); - it("empty dataSets", function () { - controller.set('dataSets', []); - controller.updateExpressions(); - expect(controller.parseExpression.called).to.be.false; - expect(controller.parseTemplateExpression.called).to.be.false; - expect(controller.parseGraphDataset.called).to.be.false; - expect(controller.get('widgetValues')).to.be.empty; - expect(controller.get('widgetMetrics')).to.be.empty; - }); - it("GAUGE widget", function () { - controller.set('expressions', [{}]); - controller.set('content.widgetType', 'GAUGE'); - controller.set('dataSets', [{}]); - //controller.updateExpressions(); - expect(controller.parseExpression.calledOnce).to.be.true; - expect(controller.parseTemplateExpression.called).to.be.false; - expect(controller.parseGraphDataset.called).to.be.false; - expect(controller.get('widgetValues')).to.not.be.empty; - expect(controller.get('widgetMetrics')).to.not.be.empty; - }); - it("NUMBER widget", function () { - controller.set('expressions', [{}]); - controller.set('content.widgetType', 'NUMBER'); - controller.set('dataSets', [{}]); - //controller.updateExpressions(); - expect(controller.parseExpression.calledOnce).to.be.true; - expect(controller.parseTemplateExpression.called).to.be.false; - expect(controller.parseGraphDataset.called).to.be.false; - expect(controller.get('widgetValues')).to.not.be.empty; - expect(controller.get('widgetMetrics')).to.not.be.empty; - }); - it("TEMPLATE widget", function () { - controller.set('expressions', [{}]); - controller.set('content.widgetType', 'TEMPLATE'); - controller.set('dataSets', [{}]); - //controller.updateExpressions(); - expect(controller.parseExpression.called).to.be.false; - expect(controller.parseTemplateExpression.calledOnce).to.be.true; - expect(controller.parseGraphDataset.called).to.be.false; - expect(controller.get('widgetValues')).to.not.be.empty; - expect(controller.get('widgetMetrics')).to.not.be.empty; - }); - it("GRAPH widget", function () { - controller.set('expressions', [{}]); - controller.set('content.widgetType', 'GRAPH'); - controller.set('dataSets', [{}]); - //controller.updateExpressions(); - expect(controller.parseExpression.called).to.be.false; - expect(controller.parseTemplateExpression.called).to.be.false; - expect(controller.parseGraphDataset.calledOnce).to.be.true; - expect(controller.get('widgetValues')).to.not.be.empty; - expect(controller.get('widgetMetrics')).to.not.be.empty; + + describe("empty dataSets", function () { + + beforeEach(function () { + controller.set('dataSets', []); + controller.updateExpressions(); + }); + + it('parseExpression is not called', function () { + expect(controller.parseExpression.called).to.be.false; + }); + it('parseTemplateExpression is not called', function () { + expect(controller.parseTemplateExpression.called).to.be.false; + }); + it('parseGraphDataset is not called', function () { + expect(controller.parseGraphDataset.called).to.be.false; + }); + it('widgetValues is empty', function () { + expect(controller.get('widgetValues')).to.be.empty; + }); + it('widgetMetrics is empty', function () { + expect(controller.get('widgetMetrics')).to.be.empty; + }); + }); + + describe("GAUGE widget", function () { + + beforeEach(function () { + controller.set('expressions', [{}]); + controller.set('content.widgetType', 'GAUGE'); + controller.set('dataSets', [{}]); + //controller.updateExpressions(); + }); + + + it('parseExpression is called once', function () { + expect(controller.parseExpression.calledOnce).to.be.true; + }); + it('parseTemplateExpression is not called', function () { + expect(controller.parseTemplateExpression.called).to.be.false; + }); + it('parseGraphDataset is not called', function () { + expect(controller.parseGraphDataset.called).to.be.false; + }); + it('widgetValues is not empty', function () { + expect(controller.get('widgetValues')).to.not.be.empty; + }); + it('widgetMetrics is not empty', function () { + expect(controller.get('widgetMetrics')).to.not.be.empty; + }); + }); + + describe("NUMBER widget", function () { + + beforeEach(function () { + controller.set('expressions', [{}]); + controller.set('content.widgetType', 'NUMBER'); + controller.set('dataSets', [{}]); + //controller.updateExpressions(); + }); + + + it('parseExpression is called once', function () { + expect(controller.parseExpression.calledOnce).to.be.true; + }); + it('parseTemplateExpression is not called', function () { + expect(controller.parseTemplateExpression.called).to.be.false; + }); + it('parseGraphDataset is not called', function () { + expect(controller.parseGraphDataset.called).to.be.false; + }); + it('widgetValues is not empty', function () { + expect(controller.get('widgetValues')).to.not.be.empty; + }); + it('widgetMetrics is not empty', function () { + expect(controller.get('widgetMetrics')).to.not.be.empty; + }); + }); + + describe("TEMPLATE widget", function () { + + beforeEach(function () { + controller.set('expressions', [{}]); + controller.set('content.widgetType', 'TEMPLATE'); + controller.set('dataSets', [{}]); + //controller.updateExpressions(); + }); + + + it('parseExpression is not called', function () { + expect(controller.parseExpression.called).to.be.false; + }); + it('parseTemplateExpression is called once', function () { + expect(controller.parseTemplateExpression.calledOnce).to.be.true; + }); + it('parseGraphDataset is not called', function () { + expect(controller.parseGraphDataset.called).to.be.false; + }); + it('widgetValues is not empty', function () { + expect(controller.get('widgetValues')).to.not.be.empty; + }); + it('widgetMetrics is not empty', function () { + expect(controller.get('widgetMetrics')).to.not.be.empty; + }); }); + + describe("GRAPH widget", function () { + + beforeEach(function () { + controller.set('expressions', [{}]); + controller.set('content.widgetType', 'GRAPH'); + controller.set('dataSets', [{}]); + //controller.updateExpressions(); + }); + + it('parseExpression is not called', function () { + expect(controller.parseExpression.called).to.be.false; + }); + it('parseTemplateExpression is not called', function () { + expect(controller.parseTemplateExpression.called).to.be.false; + }); + it('parseGraphDataset is called once', function () { + expect(controller.parseGraphDataset.calledOnce).to.be.true; + }); + it('widgetValues is not empty', function () { + expect(controller.get('widgetValues')).to.not.be.empty; + }); + it('widgetMetrics is not empty', function () { + expect(controller.get('widgetMetrics')).to.not.be.empty; + }); + }); + }); describe("#parseGraphDataset()", function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main/service_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service_test.js b/ambari-web/test/controllers/main/service_test.js index c134419..4a3d329 100644 --- a/ambari-web/test/controllers/main/service_test.js +++ b/ambari-web/test/controllers/main/service_test.js @@ -124,18 +124,28 @@ describe('App.MainServiceController', function () { e: null } ]).forEach(function(test) { - it(test.m, function() { - sinon.stub(App.router, 'get', function(k) { - if ('clusterController.isClusterDataLoaded' === k) return test.isLoaded; - return Em.get(App.router, k); + describe(test.m, function() { + + beforeEach(function () { + sinon.stub(App.router, 'get', function(k) { + if ('clusterController.isClusterDataLoaded' === k) return test.isLoaded; + return Em.get(App.router, k); + }); + sinon.stub(App.Cluster, 'find', function() { + return [test.e]; + }); }); - sinon.stub(App.Cluster, 'find', function() { - return [test.e]; + + afterEach(function () { + App.router.get.restore(); + App.Cluster.find.restore(); + }); + + it('cluster is valid', function () { + var c = mainServiceController.get('cluster'); + expect(c).to.eql(test.e); }); - var c = mainServiceController.get('cluster'); - App.router.get.restore(); - App.Cluster.find.restore(); - expect(c).to.eql(test.e); + }); }); @@ -220,28 +230,38 @@ describe('App.MainServiceController', function () { expect(Em.I18n.t.calledWith('services.service.stop.confirmButton')).to.be.ok; }); - it ("should check last checkpoint for NN before confirming stop", function() { - var mainServiceItemController = App.MainServiceItemController.create({}); - sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() { - return true; + describe("should check last checkpoint for NN before confirming stop", function() { + var mainServiceItemController; + beforeEach(function() { + mainServiceItemController = App.MainServiceItemController.create({}); + sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() { + return true; + }); + sinon.stub(App.router, 'get', function(k) { + if ('mainServiceItemController' === k) { + return mainServiceItemController; + } + return Em.get(App.router, k); + }); + sinon.stub(App.Service, 'find', function() { + return [{ + serviceName: "HDFS", + workStatus: "STARTED" + }]; + }); }); - sinon.stub(App.router, 'get', function(k) { - if ('mainServiceItemController' === k) { - return mainServiceItemController; - } - return Em.get(App.router, k); + + afterEach(function () { + mainServiceItemController.checkNnLastCheckpointTime.restore(); + App.router.get.restore(); + App.Service.find.restore(); }); - sinon.stub(App.Service, 'find', function() { - return [{ - serviceName: "HDFS", - workStatus: "STARTED" - }]; + + it('checkNnLastCheckpointTime is called once', function () { + mainServiceController.startStopAllService(event, "INSTALLED"); + expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true); }); - mainServiceController.startStopAllService(event, "INSTALLED"); - expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true); - mainServiceItemController.checkNnLastCheckpointTime.restore(); - App.router.get.restore(); - App.Service.find.restore(); + }); it ("should confirm start if state is not INSTALLED", function() { http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main/views_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/views_controller_test.js b/ambari-web/test/controllers/main/views_controller_test.js index cea1308..85c7521 100644 --- a/ambari-web/test/controllers/main/views_controller_test.js +++ b/ambari-web/test/controllers/main/views_controller_test.js @@ -29,6 +29,7 @@ describe('MainViewsController', function () { describe('#loadAmbariViews()', function () { beforeEach(function () { sinon.stub(App.ajax, 'send', Em.K); + this.stub = sinon.stub(App.router, 'get'); }); afterEach(function () { App.router.get.restore(); @@ -36,13 +37,13 @@ describe('MainViewsController', function () { }); it('should load views if the user is logged in', function () { - sinon.stub(App.router, 'get').withArgs('loggedIn').returns(true); + this.stub.withArgs('loggedIn').returns(true); mainViewsController.loadAmbariViews(); expect(App.ajax.send.calledOnce).to.be.true; }); it('should not load views if the user is not logged in', function () { - sinon.stub(App.router, 'get').withArgs('loggedIn').returns(false); + this.stub.withArgs('loggedIn').returns(false); mainViewsController.loadAmbariViews(); expect(App.ajax.send.notCalled).to.be.true; }) http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/controllers/main_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main_test.js b/ambari-web/test/controllers/main_test.js index f9f092a..2a4fe97 100644 --- a/ambari-web/test/controllers/main_test.js +++ b/ambari-web/test/controllers/main_test.js @@ -79,25 +79,33 @@ describe('App.MainController', function () { }); describe('#dataLoading', function() { + + beforeEach(function () { + this.stub = sinon.stub(App.router, 'get'); + }); + + afterEach(function () { + this.stub.restore(); + }); + it ('Should resolve promise', function() { - sinon.stub(App.router, 'get').returns(true); + this.stub.returns(true); var deffer = mainController.dataLoading(); - App.router.get.restore(); deffer.then(function(val){ expect(val).to.be.undefined; }); }); - it ('Should resolve promise', function() { - sinon.stub(App.router, 'get').returns(false); + it ('Should resolve promise (2)', function(done) { + this.stub.returns(false); setTimeout(function() { mainController.set('isClusterDataLoaded', true); },150); var deffer = mainController.dataLoading(); - App.router.get.restore(); deffer.then(function(val){ expect(val).to.be.undefined; + done(); }); }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/a487e501/ambari-web/test/router_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js index da62895..78540e7 100644 --- a/ambari-web/test/router_test.js +++ b/ambari-web/test/router_test.js @@ -496,22 +496,32 @@ describe('App.Router', function () { m: 'jwtProviderUrl is present, current location is local login url, no redirect' } ].forEach(function(test) { - it(test.m, function() { - var mockCurrentUrl = 'http://localhost:3333/#/some/hash'; - router.set('location.lastSetURL', test.lastSetURL); - sinon.stub(App.ajax, 'send', function() { - if (!test.isResolved) { - router.onAuthenticationError(test.responseData); - } - return { - complete: function() {} - }; + describe(test.m, function() { + var mockCurrentUrl; + beforeEach(function () { + mockCurrentUrl = 'http://localhost:3333/#/some/hash'; + router.set('location.lastSetURL', test.lastSetURL); + sinon.stub(App.ajax, 'send', function() { + if (!test.isResolved) { + router.onAuthenticationError(test.responseData); + } + return { + complete: function() {} + }; + }); + this.mockGetCurrentLocationUrl.returns(mockCurrentUrl); + router.getAuthenticated(); + }); + + it('redirectByURL is ' + (test.redirectCalled ? '' : 'not') + ' called', function () { + expect(router.redirectByURL.calledOnce).to.be.eql(test.redirectCalled); }); - this.mockGetCurrentLocationUrl.returns(mockCurrentUrl); - router.getAuthenticated(); - expect(router.redirectByURL.calledOnce).to.be.eql(test.redirectCalled); + + if (test.redirectCalled) { - expect(router.redirectByURL.args[0][0]).to.be.eql(JSON.parse(test.responseData.responseText).jwtProviderUrl + encodeURIComponent(mockCurrentUrl)); + it('redirectByURL is correct', function () { + expect(router.redirectByURL.args[0][0]).to.be.eql(JSON.parse(test.responseData.responseText).jwtProviderUrl + encodeURIComponent(mockCurrentUrl)); + }); } }); });
