123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830 |
- /**
- * 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/common/controls_view');
- var validator = require('utils/validator');
- var testHelpers = require('test/helpers');
- describe('App.ServiceConfigRadioButtons', function () {
- var view;
- beforeEach(function () {
- view = App.ServiceConfigRadioButtons.create();
- });
- describe('#handleDBConnectionProperty', function () {
- var cases = [
- {
- dbType: 'mysql',
- driver: 'mysql-connector-java.jar',
- serviceConfig: {
- name: 'hive_database',
- value: 'New MySQL Database',
- serviceName: 'HIVE'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'javax.jdo.option.ConnectionURL',
- displayName: 'Database URL'
- }),
- Em.Object.create({
- name: 'hive_database',
- displayName: 'Hive Database'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.2',
- rangerVersion: '0.4.0',
- propertyAppendTo1: 'javax.jdo.option.ConnectionURL',
- propertyAppendTo2: 'hive_database',
- isAdditionalView1Null: true,
- isAdditionalView2Null: true,
- title: 'Hive, embedded database'
- },
- {
- dbType: 'postgres',
- driver: 'postgresql.jar',
- serviceConfig: {
- name: 'hive_database',
- value: 'Existing PostgreSQL Database',
- serviceName: 'HIVE'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'javax.jdo.option.ConnectionURL',
- displayName: 'Database URL'
- }),
- Em.Object.create({
- name: 'hive_database',
- displayName: 'Hive Database'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.2',
- rangerVersion: '0.4.0',
- propertyAppendTo1: 'javax.jdo.option.ConnectionURL',
- propertyAppendTo2: 'hive_database',
- isAdditionalView1Null: false,
- isAdditionalView2Null: false,
- title: 'Hive, external database'
- },
- {
- dbType: 'derby',
- driver: 'driver.jar',
- serviceConfig: {
- name: 'oozie_database',
- value: 'New Derby Database',
- serviceName: 'OOZIE'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'oozie.service.JPAService.jdbc.url',
- displayName: 'Database URL'
- }),
- Em.Object.create({
- name: 'oozie_database',
- displayName: 'Oozie Database'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.2',
- rangerVersion: '0.4.0',
- propertyAppendTo1: 'oozie.service.JPAService.jdbc.url',
- propertyAppendTo2: 'oozie_database',
- isAdditionalView1Null: true,
- isAdditionalView2Null: true,
- title: 'Oozie, embedded database'
- },
- {
- dbType: 'oracle',
- driver: 'ojdbc6.jar',
- serviceConfig: {
- name: 'oozie_database',
- value: 'Existing Oracle Database',
- serviceName: 'OOZIE'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'oozie.service.JPAService.jdbc.url',
- displayName: 'Database URL'
- }),
- Em.Object.create({
- name: 'oozie_database',
- displayName: 'Oozie Database'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.2',
- rangerVersion: '0.4.0',
- propertyAppendTo1: 'oozie.service.JPAService.jdbc.url',
- propertyAppendTo2: 'oozie_database',
- isAdditionalView1Null: false,
- isAdditionalView2Null: false,
- title: 'Oozie, external database'
- },
- {
- dbType: 'mysql',
- driver: 'mysql-connector-java.jar',
- serviceConfig: {
- name: 'DB_FLAVOR',
- value: 'MYSQL',
- serviceName: 'RANGER'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'ranger.jpa.jdbc.url'
- }),
- Em.Object.create({
- name: 'DB_FLAVOR'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.2',
- rangerVersion: '0.4.0',
- propertyAppendTo1: 'ranger.jpa.jdbc.url',
- propertyAppendTo2: 'DB_FLAVOR',
- isAdditionalView1Null: true,
- isAdditionalView2Null: true,
- title: 'Ranger, HDP 2.2, external database'
- },
- {
- dbType: 'mssql',
- driver: 'sqljdbc4.jar',
- serviceConfig: {
- name: 'DB_FLAVOR',
- value: 'MSSQL',
- serviceName: 'RANGER'
- },
- controller: Em.Object.create({
- selectedService: {
- configs: [
- Em.Object.create({
- name: 'ranger.jpa.jdbc.url'
- }),
- Em.Object.create({
- name: 'DB_FLAVOR'
- })
- ]
- }
- }),
- currentStackVersion: 'HDP-2.3',
- rangerVersion: '0.5.0',
- propertyAppendTo1: 'ranger.jpa.jdbc.url',
- propertyAppendTo2: 'DB_FLAVOR',
- isAdditionalView1Null: false,
- isAdditionalView2Null: false,
- title: 'Ranger, HDP 2.3, external database'
- }
- ];
- var rangerVersion = '';
- before(function () {
- sinon.stub(Em.run, 'next', function (arg) {
- arg();
- });
- });
- beforeEach(function () {
- sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
- this.stub = sinon.stub(App, 'get');
- this.stub.withArgs('currentStackName').returns('HDP');
- sinon.stub(App.StackService, 'find', function() {
- return [Em.Object.create({
- serviceName: 'RANGER',
- serviceVersion: rangerVersion || ''
- })];
- });
- });
- afterEach(function () {
- App.get.restore();
- App.StackService.find.restore();
- view.sendRequestRorDependentConfigs.restore();
- });
- after(function () {
- Em.run.next.restore();
- });
- cases.forEach(function (item) {
- describe(item.title, function () {
- var additionalView1, additionalView2;
- beforeEach(function () {
- this.stub.withArgs('currentStackVersion').returns(item.currentStackVersion);
- rangerVersion = item.rangerVersion;
- view.reopen({controller: item.controller});
- view.setProperties({
- categoryConfigsAll: item.controller.get('selectedService.configs'),
- serviceConfig: item.serviceConfig
- });
- additionalView1 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo1).get('additionalView');
- additionalView2 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo2).get('additionalView');
- });
- it('additionalView1 is ' + (item.isAdditionalView1Null ? '' : 'not') + ' null', function () {
- expect(Em.isNone(additionalView1)).to.equal(item.isAdditionalView1Null);
- });
- it('additionalView2 is ' + (item.isAdditionalView2Null ? '' : 'not') + ' null', function () {
- expect(Em.isNone(additionalView2)).to.equal(item.isAdditionalView2Null);
- });
- if (!item.isAdditionalView2Null) {
- it('additionalView2.message is valid', function () {
- expect(additionalView2.create().get('message')).to.equal(Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(item.dbType, item.driver));
- });
- }
- });
- });
- });
- describe('#options', function () {
- var options = [
- {
- displayName: 'MySQL'
- },
- {
- displayName: 'New PostgreSQL Database'
- },
- {
- displayName: 'existing postgres db'
- },
- {
- displayName: 'sqla database: existing'
- },
- {
- displayName: 'SQL Anywhere database (New)'
- },
- {
- displayName: 'displayName'
- }
- ],
- classNames = ['mysql', 'new-postgres', 'postgres', 'sqla', 'new-sqla', undefined];
- beforeEach(function () {
- view.reopen({
- serviceConfig: Em.Object.create({
- options: options
- })
- });
- });
- it('should set class names for options', function () {
- expect(view.get('options').mapProperty('displayName')).to.eql(options.mapProperty('displayName'));
- expect(view.get('options').mapProperty('className')).to.eql(classNames);
- });
- });
- describe('#name', function () {
- var cases = [
- {
- serviceConfig: {
- radioName: 'n0',
- isOriginalSCP: true,
- isComparison: false
- },
- name: 'n0',
- title: 'original value'
- },
- {
- serviceConfig: {
- radioName: 'n1',
- isOriginalSCP: false,
- isComparison: true,
- compareConfigs: []
- },
- controller: {
- selectedVersion: 1
- },
- name: 'n1-v1',
- title: 'comparison view, original value'
- },
- {
- serviceConfig: {
- radioName: 'n2',
- isOriginalSCP: false,
- isComparison: true,
- compareConfigs: null
- },
- version: 2,
- name: 'n2-v2',
- title: 'comparison view, value to be compared with'
- },
- {
- serviceConfig: {
- radioName: 'n3',
- isOriginalSCP: false,
- isComparison: false,
- group: {
- name: 'g'
- }
- },
- name: 'n3-g',
- title: 'override value'
- }
- ];
- beforeEach(function () {
- view.reopen({
- serviceConfig: Em.Object.create()
- });
- });
- cases.forEach(function (item) {
- it(item.title, function () {
- if (item.controller) {
- view.reopen({
- controller: item.controller
- });
- }
- view.set('version', item.version);
- view.get('serviceConfig').setProperties(item.serviceConfig);
- expect(view.get('name')).to.equal(item.name);
- });
- });
- });
- describe('#dontUseHandleDbConnection', function () {
- var rangerService = Em.Object.create({
- serviceName: 'RANGER'
- });
- beforeEach(function () {
- sinon.stub(App.StackService, 'find', function () {
- return [rangerService];
- });
- });
- afterEach(function () {
- App.StackService.find.restore();
- });
- var cases = [
- {
- title: 'Should return properties for old version of Ranger',
- version: '0.1',
- result: ['DB_FLAVOR', 'authentication_method']
- },
- {
- title: 'Should return properties for old version of Ranger',
- version: '0.4.0',
- result: ['DB_FLAVOR', 'authentication_method']
- },
- {
- title: 'Should return properties for old version of Ranger',
- version: '0.4.9',
- result: ['DB_FLAVOR', 'authentication_method']
- },
- {
- title: 'Should return properties for new version of Ranger',
- version: '0.5.0',
- result: ['ranger.authentication.method']
- },
- {
- title: 'Should return properties for new version of Ranger',
- version: '1.0.0',
- result: ['ranger.authentication.method']
- },
- {
- title: 'Should return properties for new version of Ranger',
- version: '0.5.0.1',
- result: ['ranger.authentication.method']
- }
- ];
- cases.forEach(function (test) {
- it(test.title, function () {
- rangerService.set('serviceVersion', test.version);
- expect(view.get('dontUseHandleDbConnection')).to.eql(test.result);
- });
- });
- });
- });
- describe('App.ServiceConfigRadioButton', function () {
- describe('#disabled', function () {
- var cases = [
- {
- wizardControllerName: 'addServiceController',
- value: 'New MySQL Database',
- title: 'Add Service Wizard, new database',
- disabled: false
- },
- {
- wizardControllerName: 'installerController',
- value: 'New MySQL Database',
- title: 'Install Wizard, new database',
- disabled: false
- },
- {
- wizardControllerName: 'addServiceController',
- value: 'Existing MySQL Database',
- title: 'Add Service Wizard, existing database',
- disabled: false
- },
- {
- wizardControllerName: 'installerController',
- value: 'Existing MySQL Database',
- title: 'Install Wizard, existing database',
- disabled: false
- },
- {
- wizardControllerName: null,
- value: 'New MySQL Database',
- title: 'No installer, new database',
- disabled: true
- },
- {
- wizardControllerName: null,
- value: 'Existing MySQL Database',
- title: 'No installer, existing database',
- disabled: false
- }
- ];
- cases.forEach(function (item) {
- it(item.title, function () {
- var view = App.ServiceConfigRadioButton.create({
- parentView: Em.Object.create({
- serviceConfig: Em.Object.create()
- }),
- controller: Em.Object.create({
- wizardController: Em.Object.create({
- name: null
- })
- })
- });
- view.set('value', item.value);
- view.set('controller.wizardController.name', item.wizardControllerName);
- view.set('parentView.serviceConfig.isEditable', true);
- expect(view.get('disabled')).to.equal(item.disabled);
- });
- });
- it('parent view is disabled', function () {
- var view = App.ServiceConfigRadioButton.create({
- parentView: Em.Object.create({
- serviceConfig: Em.Object.create()
- })
- });
- view.set('parentView.serviceConfig.isEditable', false);
- expect(view.get('disabled')).to.be.true;
- });
- });
- });
- describe('App.CheckDBConnectionView', function () {
- describe('#masterHostName', function () {
- var cases = [
- {
- serviceName: 'OOZIE',
- value: 'h0'
- },
- {
- serviceName: 'KERBEROS',
- value: 'h1'
- },
- {
- serviceName: 'HIVE',
- value: 'h2'
- },
- {
- serviceName: 'RANGER',
- value: 'h3'
- }
- ],
- categoryConfigsAll = [
- Em.Object.create({
- name: 'oozie_server_hosts',
- value: 'h0'
- }),
- Em.Object.create({
- name: 'kdc_host',
- value: 'h1'
- }),
- Em.Object.create({
- name: 'hive_metastore_hosts',
- value: 'h2'
- }),
- Em.Object.create({
- name: 'ranger_server_hosts',
- value: 'h3'
- })
- ];
- cases.forEach(function (item) {
- it(item.serviceName, function () {
- var view = App.CheckDBConnectionView.create({
- parentView: {
- service: {
- serviceName: item.serviceName
- },
- categoryConfigsAll: categoryConfigsAll
- }
- });
- expect(view.get('masterHostName')).to.equal(item.value);
- });
- });
- });
- describe('#setResponseStatus', function () {
- var view,
- cases = [
- {
- isSuccess: 'success',
- logsPopupBefore: null,
- logsPopup: null,
- responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
- isConnectionSuccess: true,
- title: 'success, no popup displayed'
- },
- {
- isSuccess: 'success',
- logsPopupBefore: {},
- logsPopup: {
- header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.success'))
- },
- responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
- isConnectionSuccess: true,
- title: 'success, popup is displayed'
- },
- {
- isSuccess: 'error',
- logsPopupBefore: {},
- logsPopup: {
- header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error'))
- },
- responseCaption: Em.I18n.t('services.service.config.database.connection.failed'),
- isConnectionSuccess: false,
- title: 'error, popup is displayed'
- }
- ];
- beforeEach(function () {
- view = App.CheckDBConnectionView.create({
- databaseName: 'MySQL'
- });
- sinon.stub(view, 'setConnectingStatus', Em.K);
- });
- afterEach(function () {
- view.setConnectingStatus.restore();
- });
- cases.forEach(function (item) {
- describe(item.title, function () {
- beforeEach(function () {
- view.set('logsPopup', item.logsPopupBefore);
- view.setResponseStatus(item.isSuccess);
- });
- it('isRequestResolved is true', function () {
- expect(view.get('isRequestResolved')).to.be.true;
- });
- it('setConnectingStatus is called with valid arguments', function () {
- expect(view.setConnectingStatus.calledOnce).to.be.true;
- expect(view.setConnectingStatus.calledWith(false)).to.be.true;
- });
- it('responseCaption is valid', function () {
- expect(view.get('responseCaption')).to.equal(item.responseCaption);
- });
- it('isConnectionSuccess is valid', function () {
- expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
- });
- it('logsPopup is valid', function () {
- expect(view.get('logsPopup')).to.eql(item.logsPopup);
- });
- });
- });
- });
- describe('#showLogsPopup', function () {
- var view;
- beforeEach(function () {
- view = App.CheckDBConnectionView.create({
- databaseName: 'MySQL'
- });
- sinon.spy(App, 'showAlertPopup');
- });
- afterEach(function () {
- App.showAlertPopup.restore();
- });
- it('successful connection', function () {
- view.set('isConnectionSuccess', true);
- view.showLogsPopup();
- expect(App.showAlertPopup.callCount).to.equal(0);
- });
- describe('failed connection without output data, popup dismissed with Close button', function () {
- beforeEach(function () {
- view.set('isConnectionSuccess', false);
- view.set('isRequestResolved', true);
- view.set('responseFromServer', 'fail');
- view.showLogsPopup();
- });
- it('showAlertPopup is called once', function () {
- expect(App.showAlertPopup.callCount).to.equal(1);
- });
- it('logsPopup.header is valid', function () {
- expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')));
- });
- it('logsPopup.body is valid', function () {
- expect(view.get('logsPopup.body')).to.equal('fail');
- });
- it('logsPopup is null after close', function () {
- view.get('logsPopup').onClose();
- expect(view.get('logsPopup')).to.be.null;
- });
- });
- describe('check in progress with output data, popup dismissed with OK button', function () {
- var response = {
- stderr: 'stderr',
- stdout: 'stdout',
- structuredOut: 'structuredOut'
- };
- beforeEach(function () {
- view.set('isConnectionSuccess', false);
- view.set('isRequestResolved', false);
- view.set('responseFromServer', response);
- view.showLogsPopup();
- });
- it('showAlertPopup is called once', function () {
- expect(App.showAlertPopup.callCount).to.equal(1);
- });
- it('logsPopup.header is valid', function () {
- expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')));
- });
- it('logsPopup.bodyClass is valid', function () {
- expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(response);
- });
- it('logsPopup is null after primary click', function () {
- view.get('logsPopup').onPrimary();
- expect(view.get('logsPopup')).to.be.null;
- });
- });
- });
- describe("#createCustomAction()", function() {
- var view;
- beforeEach(function () {
- view = App.CheckDBConnectionView.create({
- databaseName: 'MySQL',
- getConnectionProperty: Em.K,
- masterHostName: 'host1'
- });
- this.mock = sinon.stub(App.Service, 'find');
- });
- afterEach(function () {
- this.mock.restore();
- });
- it("service not installed", function() {
- this.mock.returns(Em.Object.create({isLoaded: false}));
- view.createCustomAction();
- var args = testHelpers.findAjaxRequest('name', 'custom_action.create');
- expect(args[0]).exists;
- });
- it("service is installed", function() {
- this.mock.returns(Em.Object.create({isLoaded: true}));
- view.createCustomAction();
- var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
- expect(args[0]).exists;
- });
- });
- });
- describe('App.BaseUrlTextField', function () {
- var view = App.BaseUrlTextField.create({
- repository: Em.Object.create({
- baseUrl: 'val'
- }),
- parentView: Em.Object.create({
- uiValidation: Em.K
- })
- });
- describe('#valueWasChanged', function () {
- it('should be recalculated after value is changed', function () {
- view.setProperties({
- value: 'val',
- defaultValue: 'val'
- });
- expect(view.get('valueWasChanged')).to.be.false;
- view.set('value', 'newVal');
- expect(view.get('valueWasChanged')).to.be.true;
- });
- });
- describe('#restoreValue()', function () {
- it('should unset value', function () {
- view.setProperties({
- value: 'valNew',
- defaultValue: 'val'
- });
- view.restoreValue();
- expect(view.get('value')).to.equal('val');
- });
- });
- describe('#didInsertElement()', function () {
- it('should set defaultValue', function () {
- view.setProperties({
- value: 'valNew',
- defaultValue: 'val'
- });
- view.didInsertElement();
- expect(view.get('defaultValue')).to.equal('valNew');
- });
- });
- describe('#validate()', function () {
- beforeEach(function(){
- sinon.stub(view.get('parentView'), 'uiValidation', Em.K);
- sinon.stub(validator, 'isValidBaseUrl').returns(true);
- });
- afterEach(function(){
- view.get('parentView').uiValidation.restore();
- validator.isValidBaseUrl.restore();
- });
- it('skip validation', function () {
- view.set('repository', Em.Object.create({
- skipValidation: true
- }));
- expect(view.get('repository.hasError')).to.be.false;
- });
- it('apply validation', function () {
- view.set('repository', Em.Object.create({
- skipValidation: false
- }));
- expect(view.get('repository.hasError')).to.be.false;
- expect(validator.isValidBaseUrl.calledOnce).to.be.true;
- });
- });
- });
|