12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643 |
- /**
- * 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');
- require('controllers/wizard');
- var c;
- function getSteps(start, count) {
- var steps = [];
- for (var j = start; j <= count; j++) {
- steps.push(Em.Object.create({step: j, value: false}));
- }
- return steps;
- }
- describe('App.WizardController', function () {
- var wizardController = App.WizardController.create({});
- var totalSteps = 11;
- var ruller = d3.range(0, totalSteps);
- var i;
- beforeEach(function () {
- c = App.WizardController.create({});
- });
- describe('#setLowerStepsDisable', function () {
- var steps = getSteps(1, 10);
- wizardController.set('isStepDisabled', steps);
- steps.forEach(function (step) {
- var index = step.get('step');
- it('Steps: 10 | Disabled: ' + (index - 1), function () {
- wizardController.setLowerStepsDisable(index);
- expect(wizardController.get('isStepDisabled').filterProperty('value', true).length).to.be.equal(index - 1);
- });
- });
- });
- // isStep0 ... isStep10 tests
- App.WizardController1 = App.WizardController.extend({currentStep:''});
- var tests = [];
- for (i = 0; i < totalSteps; i++) {
- var n = ruller.slice(0);
- n.splice(i, 1);
- tests.push({i: i, n: n});
- }
- tests.forEach(function (test) {
- describe('isStep' + test.i, function () {
- var w = App.WizardController1.create();
- w.set('currentStep', test.i);
- it('Current Step is {0}, so isStep{1} is TRUE'.format(test.i, test.i), function () {
- expect(w.get('isStep' + test.i)).to.equal(true);
- });
- test.n.forEach(function (indx) {
- it('Current Step is {0}, so isStep{1} is FALSE'.format(test.i, indx), function () {
- expect(w.get('isStep' + indx)).to.equal(false);
- });
- });
- });
- });
- // isStep0 ... isStep10 tests end
- describe('#gotoStep', function() {
- var w = App.WizardController1.create();
- var steps = getSteps(0, totalSteps - 1);
- steps.forEach(function(step, index) {
- step.set('value', true);
- w.set('isStepDisabled', steps);
- it('step {0} is disabled, so gotoStep({1}) is not possible'.format(index, index), function() {
- expect(w.gotoStep(index)).to.equal(false);
- });
- });
- });
- describe('#launchBootstrapSuccessCallback', function() {
- var params = {popup: {finishLoading: function(){}}};
- beforeEach(function () {
- sinon.spy(params.popup, "finishLoading");
- });
- afterEach(function () {
- params.popup.finishLoading.restore();
- });
- it('Save bootstrapRequestId', function() {
- var data = {requestId: 123, status: 'SUCCESS', log: 'ok'};
- wizardController.launchBootstrapSuccessCallback(data, {}, params);
- expect(params.popup.finishLoading.calledWith(123, null, 'SUCCESS', 'ok')).to.be.true;
- });
- });
- describe('#getInstallOptions', function () {
- var cases = [
- {
- isHadoopWindowsStack: true,
- expected: {
- useSsh: false
- }
- },
- {
- isHadoopWindowsStack: false,
- expected: {
- useSsh: true
- }
- }
- ],
- title = 'should return {0}';
- beforeEach(function () {
- sinon.stub(wizardController, 'get')
- .withArgs('installOptionsTemplate').returns({useSsh: true})
- .withArgs('installWindowsOptionsTemplate').returns({useSsh: false});
- this.stub = sinon.stub(App, 'get');
- });
- afterEach(function () {
- App.get.restore();
- wizardController.get.restore();
- });
- cases.forEach(function (item) {
- it(title.format(item.expected), function () {
- this.stub.withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
- expect(wizardController.getInstallOptions()).to.eql(item.expected);
- });
- });
- });
- describe('#clearInstallOptions', function () {
- wizardController.setProperties({
- content: {},
- name: 'wizardController'
- });
- beforeEach(function () {
- sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
- });
- afterEach(function () {
- App.get.restore();
- });
- describe('should clear install options', function () {
- beforeEach(function () {
- wizardController.clearInstallOptions();
- });
- it('content.installOptions', function () {
- expect(wizardController.get('content.installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
- });
- it('content.hosts', function () {
- expect(wizardController.get('content.hosts')).to.eql({});
- });
- it('installOptions', function () {
- expect(wizardController.getDBProperty('installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
- });
- it('hosts', function () {
- expect(wizardController.getDBProperty('hosts')).to.eql({});
- });
- });
- });
- describe('#loadServiceConfigGroups', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperties', function() {
- return {
- serviceConfigGroups: [
- {
- hosts: ['h1']
- }
- ],
- hosts: Em.Object.create({
- h1: Em.Object.create({
- id: 'h1'
- })
- })
- };
- });
- });
- afterEach(function () {
- wizardController.getDBProperties.restore();
- });
- it('should load service confgig group', function () {
- wizardController.loadServiceConfigGroups();
- expect(wizardController.get('content.configGroups')).to.eql([
- {
- "hosts": [
- "h1"
- ]
- }
- ]);
- });
- });
- describe('#saveTasksStatuses', function () {
- it('should set status', function () {
- wizardController.saveTasksStatuses('st');
- expect(wizardController.get('content.tasksStatuses')).to.equal('st');
- });
- });
- describe('#saveSlaveComponentHosts', function () {
- beforeEach(function(){
- sinon.stub(wizardController,'getDBProperty').returns(Em.A({
- 'h1': {
- id: 1
- }
- }));
- });
- afterEach(function(){
- wizardController.getDBProperty.restore();
- });
- it('should save slave components', function () {
- var stepController = Em.Object.create({
- hosts: Em.A([
- Em.Object.create({
- hostName: 'h1',
- checkboxes: Em.A([
- Em.Object.create({title: 'hl1', checked: true})
- ])
- })
- ]),
- headers: Em.A([
- Em.Object.create({name: 'header1', label: 'hl1'})
- ])
- });
- wizardController.saveSlaveComponentHosts(stepController);
- var res = JSON.parse(JSON.stringify(wizardController.get('content.slaveComponentHosts')));
- expect(res).to.eql([
- {
- "componentName": "header1",
- "displayName": "hl1",
- "hosts": [
- {
- "group": "Default",
- "host_id": 1
- }
- ]
- }
- ]);
- });
- });
- describe('#showLaunchBootstrapPopup', function () {
- afterEach(function(){
- App.ModalPopup.show.restore();
- });
- describe('errors', function () {
- beforeEach(function () {
- sinon.stub(App.ModalPopup,'show', function (data) {
- data.finishLoading.call(c);
- });
- });
- it('should set error', function () {
- c.showLaunchBootstrapPopup(Em.K);
- expect(c.get('isError')).to.be.true;
- });
- });
- describe('#finishLoading', function () {
- var stepController = App.get('router.wizardStep3Controller'),
- cases = [
- {
- requestId: null,
- serverError: 'error',
- wizardControllerProperties: {
- isError: true,
- showFooter: true,
- showCloseButton: true,
- serverError: 'error'
- },
- stepControllerProperties: {
- isRegistrationInProgress: false,
- isBootstrapFailed: true
- },
- bootStatus: 'FAILED',
- callbackCallCount: 0,
- hideCallCount: 0,
- title: 'no request id'
- },
- {
- requestId: 0,
- status: 'ERROR',
- log: 'log',
- wizardControllerProperties: {
- isError: true,
- showFooter: true,
- showCloseButton: true,
- serverError: 'log'
- },
- stepControllerProperties: {
- isRegistrationInProgress: false,
- isBootstrapFailed: true
- },
- bootStatus: 'FAILED',
- callbackCallCount: 0,
- hideCallCount: 0,
- title: 'ERROR status'
- },
- {
- requestId: 1,
- log: 'log',
- wizardControllerProperties: {
- isError: false,
- showFooter: false,
- showCloseButton: false,
- serverError: null
- },
- stepControllerProperties: {
- isRegistrationInProgress: true,
- isBootstrapFailed: false
- },
- bootStatus: 'PENDING',
- callbackCallCount: 1,
- hideCallCount: 1,
- title: 'request accepted'
- }
- ];
- beforeEach(function () {
- c.setProperties({
- isError: false,
- showFooter: false,
- showCloseButton: false,
- serverError: null,
- hide: Em.K,
- callback: Em.K
- });
- stepController.setProperties({
- isRegistrationInProgress: true,
- isBootstrapFailed: false,
- hosts: [
- {
- bootStatus: 'PENDING'
- },
- {
- bootStatus: 'PENDING'
- }
- ]
- });
- sinon.spy(c, 'hide');
- sinon.spy(c, 'callback');
- });
- afterEach(function () {
- c.hide.restore();
- c.callback.restore();
- });
- cases.forEach(function (item) {
- describe(item.title, function () {
- var wizardControllerProperties = Em.keys(item.wizardControllerProperties),
- stepControllerProperties = Em.keys(item.stepControllerProperties);
- beforeEach(function () {
- sinon.stub(App.ModalPopup,'show', function (data) {
- data.finishLoading.call(c, item.requestId, item.serverError, item.status, item.log);
- });
- c.showLaunchBootstrapPopup(c.callback);
- });
- it('wizardControllerProperties are valid', function () {
- expect(c.getProperties.apply(c, wizardControllerProperties)).to.eql(item.wizardControllerProperties);
- });
- it('stepControllerProperties are valid', function () {
- expect(stepController.getProperties.apply(stepController, stepControllerProperties)).to.eql(item.stepControllerProperties);
- });
- it('bootStatus is valid', function () {
- expect(stepController.get('hosts').mapProperty('bootStatus').uniq()).to.eql([item.bootStatus]);
- });
- it('callback is called needed number of times', function () {
- expect(c.callback.callCount).to.equal(item.callbackCallCount);
- });
- it('hide is called needed number of times', function () {
- expect(c.hide.callCount).to.equal(item.hideCallCount);
- });
- });
- });
- });
- });
- describe('#gotoStep0', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 0 step', function () {
- wizardController.gotoStep0(Em.K);
- expect(res).to.be.equal(0);
- });
- });
- describe('#gotoStep1', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 1 step', function () {
- wizardController.gotoStep1(Em.K);
- expect(res).to.be.equal(1);
- });
- });
- describe('#gotoStep2', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 2 step', function () {
- wizardController.gotoStep2(Em.K);
- expect(res).to.be.equal(2);
- });
- });
- describe('#gotoSte3', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 3 step', function () {
- wizardController.gotoStep3(Em.K);
- expect(res).to.be.equal(3);
- });
- });
- describe('#gotoStep4', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 4 step', function () {
- wizardController.gotoStep4(Em.K);
- expect(res).to.be.equal(4);
- });
- });
- describe('#gotoStep5', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 5 step', function () {
- wizardController.gotoStep5(Em.K);
- expect(res).to.be.equal(5);
- });
- });
- describe('#gotoStep6', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 6 step', function () {
- wizardController.gotoStep6(Em.K);
- expect(res).to.be.equal(6);
- });
- });
- describe('#gotoStep7', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 7 step', function () {
- wizardController.gotoStep7(Em.K);
- expect(res).to.be.equal(7);
- });
- });
- describe('#gotoStep8', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 8 step', function () {
- wizardController.gotoStep8(Em.K);
- expect(res).to.be.equal(8);
- });
- });
- describe('#gotoStep9', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 9 step', function () {
- wizardController.gotoStep9(Em.K);
- expect(res).to.be.equal(9);
- });
- });
- describe('#gotoStep10', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'gotoStep', function(step){
- res = step;
- });
- });
- afterEach(function(){
- wizardController.gotoStep.restore();
- });
- it('should go to 10 step', function () {
- wizardController.gotoStep10(Em.K);
- expect(res).to.be.equal(10);
- });
- });
- describe('#gotoStep', function () {
- beforeEach(function(){
- sinon.stub(App.ModalPopup,'show', Em.K);
- sinon.stub(App.clusterStatus,'setClusterStatus', Em.K);
- sinon.stub(App.router,'send', Em.K);
- });
- afterEach(function(){
- App.ModalPopup.show.restore();
- App.clusterStatus.setClusterStatus.restore();
- App.router.send.restore();
- });
- it('should go to step', function () {
- wizardController.set('isStepDisabled', Em.A([
- Em.Object.create({
- step: '8',
- value: false
- })
- ]));
- wizardController.hide = Em.K;
- wizardController.set('content.controllerName','installerController');
- wizardController.set('currentStep','9');
- expect(wizardController.gotoStep('8')).to.be.true;
- });
- });
- describe('#launchBootstrap', function () {
- beforeEach(function(){
- sinon.stub(wizardController,'showLaunchBootstrapPopup').returns({
- name: 'popup'
- });
- });
- afterEach(function(){
- wizardController.showLaunchBootstrapPopup.restore();
- });
- it('should return popup', function () {
- expect(wizardController.launchBootstrap()).to.be.eql({
- name: 'popup'
- });
- });
- });
- describe('#save', function () {
- var res;
- beforeEach(function () {
- sinon.stub(wizardController,'setDBProperty', function(data){
- res = data;
- });
- sinon.stub(wizardController,'toJSInstance').returns('val');
- });
- afterEach(function () {
- wizardController.setDBProperty.restore();
- wizardController.toJSInstance.restore();
- });
- it('should save data', function () {
- wizardController.save('name');
- expect(res).to.be.equal('name');
- });
- });
- describe('#installServicesSuccessCallback', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'saveClusterStatus', function(data){
- res = JSON.parse(JSON.stringify(data));
- });
- sinon.stub(App,'dateTime').returns('22');
- });
- afterEach(function(){
- wizardController.saveClusterStatus.restore();
- App.dateTime.restore();
- });
- it('should call callbeck with data', function () {
- var jsonData = {
- Requests: {
- id: 1
- }
- };
- wizardController.installServicesSuccessCallback(jsonData);
- expect(res).to.be.eql({
- "status": "PENDING",
- "requestId": 1,
- "isInstallError": false,
- "isCompleted": false,
- "installStartTime": "22"
- });
- });
- });
- describe('#installServices', function () {
- var res;
- beforeEach(function(){
- sinon.stub(wizardController,'saveClusterStatus', function(data){
- res = JSON.parse(JSON.stringify(data));
- });
- });
- afterEach(function(){
- wizardController.saveClusterStatus.restore();
- });
- it('should call callbeck with data', function () {
- wizardController.set('content', Em.Object.create({
- cluster: {
- oldRequestsId: '1'
- }
- }));
- wizardController.installServices(true);
- expect(res).to.be.eql({
- "status": "PENDING"
- });
- });
- });
- describe('#saveInstalledHosts', function () {
- beforeEach(function(){
- sinon.stub(wizardController,'getDBProperty').returns({
- 'h1': {
- id: 1,
- status: '',
- name: 'h1'
- }
- });
- });
- afterEach(function(){
- wizardController.getDBProperty.restore();
- });
- it('should save installed hosts', function () {
- var stepController = Em.Object.create({
- hosts: Em.A([
- Em.Object.create({
- hostName: 'h1',
- name: 'h1',
- status: 'st',
- message: 'ms',
- checkboxes: Em.A([
- Em.Object.create({title: 'hl1', checked: true})
- ])
- })
- ])
- });
- wizardController.saveInstalledHosts(stepController);
- var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
- expect(res).to.eql({
- "h1": {
- "id": 1,
- "status": "st",
- "name": "h1",
- "message": "ms"
- }
- });
- });
- });
- describe('#saveConfirmedHosts', function () {
- beforeEach(function(){
- sinon.stub(wizardController,'getDBProperty').returns({
- 'h1': {
- id: 1,
- status: '',
- name: 'h1'
- }
- });
- });
- afterEach(function(){
- wizardController.getDBProperty.restore();
- });
- it('should save confirmed hosts', function () {
- var stepController = Em.Object.create({
- confirmedHosts: Em.A([
- {
- name: 'h2',
- cpu: '1',
- isInstalled: true
- }
- ])
- });
- wizardController.set('content.hosts', {
- 'h1': {
- isInstalled: false,
- bootStatus: 'REGISTERED'
- },
- 'h2': {
- isInstalled: true,
- bootStatus: 'REGISTERED'
- }
- });
- wizardController.saveConfirmedHosts(stepController);
- var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
- expect(res).to.eql({
- "h2": {
- "isInstalled": true,
- "bootStatus": "REGISTERED"
- }
- });
- });
- });
- describe('#loadTasksStatuses', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperty').returns('st');
- });
- afterEach(function () {
- wizardController.getDBProperty.restore();
- });
- it('should load status', function () {
- wizardController.loadTasksStatuses();
- expect(wizardController.get('content.tasksStatuses')).to.equal('st');
- });
- });
- describe('#saveTasksRequestIds', function () {
- it('should save id', function () {
- wizardController.saveTasksRequestIds('st');
- expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
- });
- });
- describe('#loadTasksRequestIds', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperty').returns('st');
- });
- afterEach(function () {
- wizardController.getDBProperty.restore();
- });
- it('should load status', function () {
- wizardController.loadTasksRequestIds();
- expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
- });
- });
- describe('#saveRequestIds', function () {
- it('should save id', function () {
- wizardController.saveRequestIds('st');
- expect(wizardController.get('content.requestIds')).to.equal('st');
- });
- });
- describe('#load', function () {
- it('should clear install options', function () {
- var name = 'Name';
- wizardController.set('get'+name.capitalize(), function() {return 'res';});
- wizardController.load(name, true);
- expect(wizardController.get('content.' + name)).to.equal('res');
- });
- });
- describe('#usersLoading', function () {
- beforeEach(function(){
- sinon.stub(App.MainAdminServiceAccountsController,'create').returns({
- loadUsers: function() {},
- get: function(type) {
- if (type === 'dataIsLoaded') {
- return true;
- }
- return Em.Object.create({
- hdfsUser: {
- name: 'user'
- }
- });
- }
- });
- });
- afterEach(function(){
- App.MainAdminServiceAccountsController.create.restore();
- });
- it('should load users', function () {
- wizardController.set('content.hdfsUser', true);
- wizardController.usersLoading().then(function(data){
- expect(data).to.be.undefined;
- });
- });
- });
- describe('#loadConfirmedHosts', function () {
- beforeEach(function(){
- sinon.stub(App.db, 'getHosts').returns(Em.A([
- Em.Object.create({
- name: 'h1'
- })
- ]));
- });
- afterEach(function(){
- App.db.getHosts.restore();
- });
- it('should load hosts from db', function () {
- wizardController.loadConfirmedHosts();
- var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
- expect(res).to.eql([
- {
- "name": "h1"
- }
- ]);
- });
- });
- describe('#loadServicesFromServer', function () {//TODO
- var res;
- beforeEach(function(){
- sinon.stub(App.StackService, 'find').returns(Em.A([
- Em.Object.create({
- isSelected: false,
- isInstalled: false,
- serviceName: 's1'
- })
- ]));
- sinon.stub(App.Service, 'find').returns(Em.A([
- Em.Object.create({
- isSelected: false,
- isInstalled: false,
- serviceName: 's1'
- })
- ]));
- sinon.stub(wizardController, 'setDBProperty', function(data) {
- res = data;
- });
- });
-
- afterEach(function () {
- App.StackService.find.restore();
- App.Service.find.restore();
- wizardController.setDBProperty.restore();
- });
- it('should load services from server', function () {
- wizardController.loadServicesFromServer();
- expect(res).to.be.equal('services');
- });
- });
- describe('#loadRequestIds', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperty').returns('st');
- });
- afterEach(function () {
- wizardController.getDBProperty.restore();
- });
- it('should load status', function () {
- wizardController.loadRequestIds();
- expect(wizardController.get('content.requestIds')).to.equal('st');
- });
- });
- describe('#loadServiceComponentsSuccessCallback', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperties', function() {
- return {
- selectedServiceNames: ['a','b'],
- installedServiceNames: ['c','d']
- };
- });
- sinon.stub(App.stackServiceMapper, 'mapStackServices', Em.K);
- });
- afterEach(function () {
- wizardController.getDBProperties.restore();
- App.stackServiceMapper.mapStackServices.restore();
- });
- it('should load json data', function () {
- var jsonData = {
- items: [
- {
- StackServices: {
- isSelected: false,
- service_name: 'a'
- }
- },
- {
- StackServices: {
- isSelected: false,
- service_name: 'none'
- }
- }
- ]
- };
- wizardController.loadServiceComponentsSuccessCallback(jsonData);
- var exp = {
- "items": [
- {
- "StackServices": {
- "isSelected": false,
- "service_name": "a",
- "is_selected": true,
- "is_installed": false
- }
- },
- {
- "StackServices": {
- "isSelected": false,
- "service_name": "none",
- "is_selected": false,
- "is_installed": false
- }
- }
- ]
- };
- expect(jsonData).to.eql(exp);
- });
- });
- describe('#setInfoForStep9', function () {
- var res;
- beforeEach(function () {
- sinon.stub(wizardController, 'getDBProperty').returns(Em.Object.create({
- status: {},
- message: {},
- logTasks: {},
- tasks: {},
- progress: {}
- }));
- sinon.stub(wizardController, 'setDBProperty', function(title,data) {
- res = data;
- });
- });
- afterEach(function () {
- wizardController.getDBProperty.restore();
- wizardController.setDBProperty.restore();
- });
- it('should return info for step 9', function () {
- wizardController.setInfoForStep9();
- var exp = {
- "status": {
- "status": "pending",
- "message": "Waiting",
- "logTasks": [],
- "tasks": [],
- "progress": "0"
- },
- "message": {
- "status": "pending",
- "message": "Waiting",
- "logTasks": [],
- "tasks": [],
- "progress": "0"
- },
- "logTasks": {
- "status": "pending",
- "message": "Waiting",
- "logTasks": [],
- "tasks": [],
- "progress": "0"
- },
- "tasks": {
- "status": "pending",
- "message": "Waiting",
- "logTasks": [],
- "tasks": [],
- "progress": "0"
- },
- "progress": {
- "status": "pending",
- "message": "Waiting",
- "logTasks": [],
- "tasks": [],
- "progress": "0"
- }
- };
- res = JSON.parse(JSON.stringify(res));
- expect(res).to.eql(exp);
- });
- });
- describe('#saveServiceConfigProperties', function () {
- beforeEach(function () {
- c.set('content', {});
- sinon.stub(c, 'setDBProperties', Em.K);
- sinon.stub(c, 'getDBProperty').withArgs('fileNamesToUpdate').returns([]);
- sinon.stub(App.config, 'shouldSupportFinal').returns(true);
- });
- afterEach(function () {
- c.setDBProperties.restore();
- c.getDBProperty.restore();
- App.config.shouldSupportFinal.restore();
- });
- var kerberosStepController = Em.Object.create({
- installedServiceNames: ['KERBEROS'],
- stepConfigs: [
- Em.Object.create({
- serviceName: 'KERBEROS',
- configs: [
- Em.Object.create({
- id: 'id',
- name: 'admin_password',
- value: 'value',
- defaultValue: 'defaultValue',
- description: 'description',
- serviceName: 'serviceName',
- domain: 'domain',
- isVisible: true,
- isNotDefaultValue: true,
- isFinal: true,
- defaultIsFinal: true,
- supportsFinal: true,
- filename: 'krb5-conf.xml',
- displayType: 'string',
- isRequiredByAgent: true,
- hasInitialValue: true,
- isRequired: true,
- group: {name: 'group'},
- showLabel: true,
- category: 'some_category'
- }),
- Em.Object.create({
- id: 'id',
- name: 'admin_principal',
- value: 'value',
- defaultValue: 'defaultValue',
- description: 'description',
- serviceName: 'serviceName',
- domain: 'domain',
- isVisible: true,
- isNotDefaultValue: true,
- isFinal: true,
- defaultIsFinal: true,
- supportsFinal: true,
- filename: 'krb5-conf.xml',
- displayType: 'string',
- isRequiredByAgent: true,
- hasInitialValue: true,
- isRequired: true,
- group: {name: 'group'},
- showLabel: true,
- category: 'some_category'
- })
- ]
- })
- ]
- });
- var stepController = Em.Object.create({
- installedServiceNames: ['HDFS'],
- stepConfigs: [
- Em.Object.create({
- serviceName: 'HDFS',
- configs: [
- Em.Object.create({
- id: 'id',
- name: 'name',
- value: 'value',
- defaultValue: 'defaultValue',
- description: 'description',
- serviceName: 'serviceName',
- domain: 'domain',
- isVisible: true,
- isNotDefaultValue: true,
- isFinal: true,
- defaultIsFinal: true,
- supportsFinal: true,
- filename: 'filename',
- displayType: 'string',
- isRequiredByAgent: true,
- hasInitialValue: true,
- isRequired: true,
- group: {name: 'group'},
- showLabel: true,
- category: 'some_category'
- })
- ]
- }),
- Em.Object.create({
- serviceName: 'YARN',
- configs: [
- Em.Object.create({
- id: 'id',
- name: 'name',
- value: 'value',
- defaultValue: 'defaultValue',
- description: 'description',
- serviceName: 'serviceName',
- domain: 'domain',
- isVisible: true,
- isFinal: true,
- defaultIsFinal: true,
- supportsFinal: true,
- filename: 'filename',
- displayType: 'string',
- isRequiredByAgent: true,
- hasInitialValue: true,
- isRequired: true,
- group: {name: 'group'},
- showLabel: true,
- category: 'some_category'
- })
- ]
- })
- ]});
- it('should save configs to content.serviceConfigProperties', function () {
- c.saveServiceConfigProperties(stepController);
- var saved = c.get('content.serviceConfigProperties');
- expect(saved.length).to.equal(2);
- expect(saved[0].category).to.equal('some_category');
- });
- it('should not save admin_principal or admin_password to the localStorage', function () {
- c.saveServiceConfigProperties(kerberosStepController);
- var saved = c.get('content.serviceConfigProperties');
- expect(saved.everyProperty('value', '')).to.be.true;
- });
- });
- describe('#enableStep', function () {
- beforeEach(function () {
- c.set('isStepDisabled', [
- Em.Object.create({step: 1, value: true}),
- Em.Object.create({step: 2, value: true}),
- Em.Object.create({step: 3, value: true}),
- Em.Object.create({step: 4, value: true}),
- Em.Object.create({step: 5, value: true}),
- Em.Object.create({step: 6, value: true}),
- Em.Object.create({step: 7, value: true})
- ]);
- });
- it('should update 1st value in isStepDisabled', function () {
- c.enableStep(1);
- expect(c.get('isStepDisabled')[0].get('value')).to.be.false;
- });
- it('should update 6th value in isStepDisabled', function () {
- c.enableStep(7);
- expect(c.get('isStepDisabled')[6].get('value')).to.be.false;
- });
- });
- describe('#allHosts', function () {
- it('should return all hosts', function () {
- var hosts = {
- 'h1': {hostComponents: ['c1', 'c2'], disk_info: [{size: 2, available: 1}]},
- 'h2': {hostComponents: ['c3', 'c4'], disk_info: [{size: 2, available: 1}]}
- };
- var content = Em.Object.create({
- hosts: hosts
- });
- c.set('content', content);
- var exp = [
- {
- "id": "h1",
- "hostName": "h1",
- "publicHostName": "h1",
- "diskInfo": [
- {
- "size": 2,
- "available": 1
- }
- ],
- "diskTotal": 0.0000019073486328125,
- "diskFree": 9.5367431640625e-7,
- "disksMounted": 1,
- "osType": 0,
- "osArch": 0,
- "ip": 0,
- "hostComponents": [
- {
- "componentName": "c1",
- "displayName": "C1"
- },
- {
- "componentName": "c2",
- "displayName": "C2"
- }
- ]
- },
- {
- "id": "h2",
- "hostName": "h2",
- "publicHostName": "h2",
- "diskInfo": [
- {
- "size": 2,
- "available": 1
- }
- ],
- "diskTotal": 0.0000019073486328125,
- "diskFree": 9.5367431640625e-7,
- "disksMounted": 1,
- "osType": 0,
- "osArch": 0,
- "ip": 0,
- "hostComponents": [
- {
- "componentName": "c3",
- "displayName": "C3"
- },
- {
- "componentName": "c4",
- "displayName": "C4"
- }
- ]
- }
- ];
- var res = JSON.parse(JSON.stringify(c.get('allHosts')));
- expect(res).to.be.eql(exp);
- });
- });
- describe('#getSlaveComponentHosts', function () {
- beforeEach(function () {
- sinon.stub(App.Service, 'find').returns(Em.A([
- Em.Object.create({
- serviceName: 's1'
- })
- ]));
- sinon.stub(App.StackService, 'find').returns(Em.A([
- Em.Object.create({
- serviceName: 's2',
- isSelected: true
- })
- ]));
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.A([
- Em.Object.create({componentName: 'DATANODE', serviceName: 's1', isSlave: true}),
- Em.Object.create({componentName: 'c2', serviceName: 's2', isSlave: true})
- ]));
- sinon.stub(App.HostComponent, 'find').returns(Em.A([
- Em.Object.create({
- componentName: 'DATANODE',
- hostName: 'h1'
- })
- ]));
- });
- afterEach(function () {
- App.Service.find.restore();
- App.HostComponent.find.restore();
- App.StackService.find.restore();
- App.StackServiceComponent.find.restore();
- });
- it('should return slave components', function () {
- var res = JSON.parse(JSON.stringify(c.getSlaveComponentHosts()));
- var exp = [
- {
- "componentName": "DATANODE",
- "displayName": "DataNode",
- "hosts": [
- {
- "group": "Default",
- "hostName": "h1",
- "isInstalled": true
- }
- ],
- "isInstalled": true
- },
- {
- "componentName": "CLIENT",
- "displayName": "Client",
- "hosts": [],
- "isInstalled": true
- },
- {
- "componentName": "c2",
- "displayName": "C2",
- "hosts": [
- {
- "group": "Default",
- "hostName": "h1",
- "isInstalled": false
- }
- ],
- "isInstalled": false
- }
- ];
- expect(res).to.be.eql(exp);
- });
- });
- describe('#setSkipSlavesStep', function () {
- var step = 6,
- cases = [
- {
- services: [
- {
- hasSlave: true,
- hasNonMastersWithCustomAssignment: true
- }
- ],
- skipSlavesStep: false,
- title: 'service with customizable slave selected'
- },
- {
- services: [
- {
- hasClient: true,
- hasNonMastersWithCustomAssignment: true
- }
- ],
- skipSlavesStep: false,
- title: 'service with customizable client selected'
- },
- {
- services: [
- {
- hasSlave: true,
- hasNonMastersWithCustomAssignment: false
- },
- {
- hasClient: true,
- hasNonMastersWithCustomAssignment: false
- }
- ],
- skipSlavesStep: true,
- title: 'no service with customizable slaves or clients selected'
- },
- {
- services: [
- {
- hasSlave: false,
- hasClient: false
- }
- ],
- skipSlavesStep: true,
- title: 'no service with slaves or clients selected'
- }
- ];
- beforeEach(function () {
- c.reopen({
- isStepDisabled: [
- Em.Object.create({
- step: 6
- })
- ],
- content: {}
- });
- });
- cases.forEach(function (item) {
- it(item.title, function () {
- c.setSkipSlavesStep(item.services, step);
- expect(Boolean(c.get('isStepDisabled').findProperty('step', step).get('value'))).to.equal(item.skipSlavesStep);
- });
- });
- });
- describe('#toJSInstance', function () {
- var testCases = [
- {
- o: {'test': 'test'},
- e: {'test': 'test'}
- },
- {
- o: {'test': Em.Object.create()},
- e: {'test': {}}
- },
- {
- o: {'test': Em.Object.create({'test': {}})},
- e: {'test': {'test': {}}}
- },
- {
- o: [],
- e: []
- },
- {
- o: Em.A([[]]),
- e: [[]]
- },
- {
- o: 11,
- e: 11
- },
- {
- o: '11',
- e: '11'
- },
- {
- o: null,
- e: null
- }
- ];
- testCases.forEach(function (testCase, index) {
- it('should convert objects and arrays to pure JS objects and arrays (' + (index + 1) + ')', function () {
- expect(c.toJSInstance(testCase.o)).to.eql(testCase.e);
- });
- });
- });
- describe('#loadConfigThemes', function() {
- beforeEach(function () {
- sinon.stub(wizardController, 'loadConfigThemeForServices').returns({
- always: Em.clb
- });
- sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(true);
- sinon.stub(App.config, 'loadConfigsFromStack').returns({
- done: Em.clb
- });
- sinon.stub(App.StackService, 'find').returns(Em.A([
- Em.Object.create({
- isSelected: true,
- serviceName: 's1'
- })
- ]));
- this.stub = sinon.stub(App, 'get');
- });
- afterEach(function () {
- App.get.restore();
- App.StackService.find.restore();
- App.config.loadConfigsFromStack.restore();
- App.themesMapper.generateAdvancedTabs.restore();
- wizardController.loadConfigThemeForServices.restore();
- });
- it('Should load config themes', function(done) {
- this.stub.returns(true);
- wizardController.loadConfigThemes().then(function() {
- done();
- });
- });
- it('Should load config themes (2)', function(done) {
- this.stub.returns(false);
- wizardController.loadConfigThemes().then(function() {
- done();
- });
- });
- });
- describe('#dataLoading', function () {
- var clusterController = Em.Object.create({
- isLoaded: false
- });
- beforeEach(function(){
- sinon.stub(App.router,'get').returns(clusterController);
- sinon.stub(wizardController, 'connectOutlet', Em.K);
- clusterController.set('isLoaded', false);
- });
- afterEach(function(){
- App.router.get.restore();
- wizardController.connectOutlet.restore();
- });
- it('should load data', function () {
- clusterController.set('isLoaded', true);
- wizardController.dataLoading().then(function(data){
- expect(data).to.be.undefined;
- });
- });
- it('should load data after 25ms', function () {
- clusterController.set('isLoaded', false);
- setTimeout(function(){
- clusterController.set('isLoaded', true);
- },25);
- wizardController.dataLoading().then(function(data){
- expect(data).to.be.undefined;
- });
- });
- });
- describe('#saveMasterComponentHosts', function () {
- var stepController = Em.Object.create({
- selectedServicesMasters: [
- Em.Object.create({
- display_name: 'd0',
- component_name: 'c0',
- selectedHost: 'h0',
- serviceId: 's0',
- isInstalled: true
- }),
- Em.Object.create({
- display_name: 'd1',
- component_name: 'c1',
- selectedHost: 'h1',
- serviceId: 's1',
- isInstalled: false
- })
- ]
- }),
- masterComponentHosts = [
- {
- display_name: 'd0',
- component: 'c0',
- hostName: 'h0',
- serviceId: 's0',
- isInstalled: true
- },
- {
- display_name: 'd1',
- component: 'c1',
- hostName: 'h1',
- serviceId: 's1',
- isInstalled: false
- }
- ];
- beforeEach(function () {
- sinon.stub(wizardController, 'setDBProperty', Em.K);
- });
- afterEach(function () {
- wizardController.setDBProperty.restore();
- });
- it('should save master component hosts', function () {
- wizardController.saveMasterComponentHosts(stepController);
- expect(wizardController.setDBProperty.calledOnce).to.be.true;
- expect(wizardController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
- expect(wizardController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
- });
- });
- describe('#clearMasterComponentHosts', function () {
- beforeEach(function () {
- sinon.stub(wizardController, 'setDBProperty', Em.K);
- });
- afterEach(function () {
- wizardController.setDBProperty.restore();
- });
- it('should clear master component hosts', function () {
- wizardController.set('content.masterComponentHosts', {});
- wizardController.clearMasterComponentHosts();
- expect(wizardController.setDBProperty.calledOnce).to.be.true;
- expect(wizardController.setDBProperty.calledWith('masterComponentHosts', null)).to.be.true;
- expect(wizardController.get('content.masterComponentHosts')).to.be.null;
- });
- });
- describe('#loadRecommendations', function () {
- beforeEach(function () {
- sinon.stub(c, 'getDBProperty').returns({});
- });
- afterEach(function () {
- c.getDBProperty.restore();
- });
- it('should set recommendations', function () {
- c.set('content', {});
- c.loadRecommendations();
- expect(c.get('content.recommendations')).to.eql({});
- });
- });
- });
|