Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
AMBARI-25097 Cover views of reassign wizard with unit tests
  • Loading branch information
atkach committed Jan 10, 2019
1 parent e8af382 commit 5f329b9f858c292f7b6aeae4d93b434489278c1b
Showing 9 changed files with 549 additions and 29 deletions.
@@ -377,6 +377,11 @@ var files = [
'test/views/main/charts/heatmap_test',
'test/views/main/charts/heatmap/heatmap_host_test',
'test/views/main/service/item_test',
'test/views/main/service/reassign/step1_view_test',
'test/views/main/service/reassign/step2_view_test',
'test/views/main/service/reassign/step3_view_test',
'test/views/main/service/reassign/step4_view_test',
'test/views/main/service/reassign/step5_view_test',
'test/views/main/service/manage_config_groups_view_test',
'test/views/main/service/reassign_view_test',
'test/views/main/service/reconfigure_test',
@@ -21,40 +21,35 @@ var App = require('app');
var stringUtils = require('utils/string_utils');

App.ReassignMasterWizardStep1View = Em.View.extend({


templateName: require('templates/main/service/reassign/step1'),

message: function () {
var componentName = this.get('controller.content.reassign.component_name');
var listOfServices;
var installedServices = App.Service.find().mapProperty('serviceName');

if(this.get('controller.content.componentsToStopAllServices').contains(componentName)) {
if (this.get('controller.content.componentsToStopAllServices').contains(componentName)) {
listOfServices = installedServices;
} else {
listOfServices = this.get('controller.target.reassignMasterController.relatedServicesMap')[componentName];
if(!listOfServices || !listOfServices.length) {
listOfServices = installedServices.filter(function (service) {
return service != 'HDFS';
});
if (!listOfServices || !listOfServices.length) {
listOfServices = installedServices.reject(service => service === 'HDFS');
} else { //not display any service which is not installed
var installedServicesToStop = listOfServices.filter(function (service) {
return installedServices.contains(service);
});
listOfServices = installedServicesToStop;
listOfServices = listOfServices.filter(service => installedServices.contains(service));
}
}

var messages = [
Em.I18n.t('services.reassign.step1.message1').format(this.get('controller.content.reassign.display_name')),
Em.I18n.t('services.reassign.step1.message3').format(stringUtils.getFormattedStringFromArray(listOfServices),
this.get('controller.content.reassign.display_name'))
];
if (this.get('controller.content.hasManualSteps')) {
messages.splice(1,0, Em.I18n.t('services.reassign.step1.message2').format(this.get('controller.content.reassign.display_name')));
messages.splice(1, 0, Em.I18n.t('services.reassign.step1.message2').format(this.get('controller.content.reassign.display_name')));
}

return messages;
}.property('controller.content.reassign.display_name','controller.content.hasManualSteps'),

templateName: require('templates/main/service/reassign/step1')

}.property('controller.content.reassign.display_name', 'controller.content.hasManualSteps')

});
@@ -30,16 +30,16 @@ App.ReassignMasterWizardStep3View = Em.View.extend({
didInsertElement: function () {
this.get('controller').loadStep();
},

jdbcSetupMessage: function() {
if(['HIVE_SERVER', 'HIVE_METASTORE', 'OOZIE_SERVER'].contains(this.get('controller.content.reassign.component_name'))) {
if(this.get('controller.content.reassign.component_name') === 'OOZIE_SERVER' && this.get('controller.content.databaseType') === 'derby') {
return false;
jdbcSetupMessage: function () {
if (['HIVE_SERVER', 'HIVE_METASTORE', 'OOZIE_SERVER'].contains(this.get('controller.content.reassign.component_name'))) {
if (this.get('controller.content.reassign.component_name') === 'OOZIE_SERVER' && this.get('controller.content.databaseType') === 'derby') {
return '';
}

return Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(this.get('controller.content.databaseType'), this.get('controller.content.databaseType'));
}

return false;
return '';
}.property('controller.content.reassign.display_name', 'controller.content.databaseType')
});
@@ -18,14 +18,14 @@


var App = require('app');
var stringUtils = require('utils/string_utils');

App.ReassignMasterWizardStep5View = Em.View.extend({

templateName: require('templates/main/service/reassign/step5'),

manualCommands: function () {
if (!this.get('controller.content.componentsWithManualCommands').contains(this.get('controller.content.reassign.component_name'))) {
const componentName = this.get('controller.content.reassign.component_name');
if (!this.get('controller.content.componentsWithManualCommands').contains(componentName)) {
return '';
}
var
@@ -37,7 +37,7 @@ App.ReassignMasterWizardStep5View = Em.View.extend({
ha = '',
user = this.get('controller.content.hdfsUser'), path;

if (this.get('controller.content.reassign.component_name') === 'NAMENODE' && App.get('isHaEnabled')) {
if (componentName === 'NAMENODE' && App.get('isHaEnabled')) {
ha = '_ha';
var nnStartedHost = this.get('controller.content.masterComponentHosts').filterProperty('component', 'NAMENODE').mapProperty('hostName').without(sourceHost).without(targetHost);
}
@@ -0,0 +1,128 @@
/**
* 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('views/main/service/reassign/step1_view');
var stringUtils = require('utils/string_utils');

var view;

function getView() {
return App.ReassignMasterWizardStep1View.create();
}

describe('App.ReassignMasterWizardStep1View', function () {

beforeEach(function() {
view = getView();
});

describe('#message', function() {
beforeEach(function() {
sinon.stub(App.Service, 'find').returns([{serviceName: 'S1'}, {serviceName: 'HDFS'}]);
});
afterEach(function() {
App.Service.find.restore();
});

it('should return message with all installed services', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'C1',
display_name: 'c1'
},
componentsToStopAllServices: ['C1']
}
}));
view.propertyDidChange('message');
expect(view.get('message')).to.be.eql([
Em.I18n.t('services.reassign.step1.message1').format('c1'),
Em.I18n.t('services.reassign.step1.message3').format(stringUtils.getFormattedStringFromArray(['S1', 'HDFS']), 'c1')
]);
});

it('should return message with all installed services, has manual steps', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'C1',
display_name: 'c1'
},
componentsToStopAllServices: ['C1'],
hasManualSteps: true
}
}));
view.propertyDidChange('message');
expect(view.get('message')).to.be.eql([
Em.I18n.t('services.reassign.step1.message1').format('c1'),
Em.I18n.t('services.reassign.step1.message2').format('c1'),
Em.I18n.t('services.reassign.step1.message3').format(stringUtils.getFormattedStringFromArray(['S1', 'HDFS']), 'c1')
]);
});

it('should return message with non-HDFS services', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'C1',
display_name: 'c1'
},
componentsToStopAllServices: []
},
target: {
reassignMasterController: {
relatedServicesMap: {}
}
}
}));
view.propertyDidChange('message');
expect(view.get('message')).to.be.eql([
Em.I18n.t('services.reassign.step1.message1').format('c1'),
Em.I18n.t('services.reassign.step1.message3').format(stringUtils.getFormattedStringFromArray(['S1']), 'c1')
]);
});

it('should return message with related services', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'C1',
display_name: 'c1'
},
componentsToStopAllServices: []
},
target: {
reassignMasterController: {
relatedServicesMap: {
'C1': ['S2', 'S1']
}
}
}
}));
view.propertyDidChange('message');
expect(view.get('message')).to.be.eql([
Em.I18n.t('services.reassign.step1.message1').format('c1'),
Em.I18n.t('services.reassign.step1.message3').format(stringUtils.getFormattedStringFromArray(['S1']), 'c1')
]);
});

});

});

@@ -0,0 +1,74 @@
/**
* 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('views/main/service/reassign/step2_view');

var view;

function getView() {
return App.ReassignMasterWizardStep2View.create();
}

describe('App.ReassignMasterWizardStep2View', function () {

beforeEach(function() {
view = getView();
});

describe('#alertMessage', function() {
beforeEach(function() {
sinon.stub(App, 'get').returns(true);
});
afterEach(function() {
App.get.restore();
});

it('should return NAMENODE alert', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'NAMENODE',
display_name: 'Namenode'
}
}
}));
view.propertyDidChange('alertMessage');
expect(view.get('alertMessage')).to.be.equal(
Em.I18n.t('services.reassign.step2.body.namenodeHA').format('Namenode')
);
});

it('should return component alert', function() {
view.set('controller', Em.Object.create({
content: {
reassign: {
component_name: 'C1',
display_name: 'c1'
}
}
}));
view.propertyDidChange('alertMessage');
expect(view.get('alertMessage')).to.be.equal(
Em.I18n.t('services.reassign.step2.body').format('c1')
);
});
});

});

0 comments on commit 5f329b9

Please sign in to comment.