config_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('config');
  20. require('utils/configs_collection');
  21. require('utils/config');
  22. require('models/service/hdfs');
  23. var setups = require('test/init_model_test');
  24. describe('App.config', function () {
  25. describe('#trimProperty',function() {
  26. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  27. var tests = [
  28. {
  29. config: {
  30. displayType: 'directory',
  31. value: ' /a /b /c'
  32. },
  33. e: '/a,/b,/c'
  34. },
  35. {
  36. config: {
  37. displayType: 'directories',
  38. value: ' /a /b '
  39. },
  40. e: '/a,/b'
  41. },
  42. {
  43. config: {
  44. displayType: 'directories',
  45. name: 'dfs.datanode.data.dir',
  46. value: ' [DISK]/a [SSD]/b '
  47. },
  48. e: '[DISK]/a,[SSD]/b'
  49. },
  50. {
  51. config: {
  52. displayType: 'directories',
  53. name: 'dfs.datanode.data.dir',
  54. value: '/a,/b, /c\n/d,\n/e /f'
  55. },
  56. e: '/a,/b,/c,/d,/e,/f'
  57. },
  58. {
  59. config: {
  60. displayType: 'host',
  61. value: ' localhost '
  62. },
  63. e: 'localhost'
  64. },
  65. {
  66. config: {
  67. displayType: 'password',
  68. value: ' passw ord '
  69. },
  70. e: ' passw ord '
  71. },
  72. {
  73. config: {
  74. displayType: 'string',
  75. value: ' value'
  76. },
  77. e: ' value'
  78. },
  79. {
  80. config: {
  81. displayType: 'string',
  82. value: ' value'
  83. },
  84. e: ' value'
  85. },
  86. {
  87. config: {
  88. displayType: 'string',
  89. value: 'http://localhost ',
  90. name: 'javax.jdo.option.ConnectionURL'
  91. },
  92. e: 'http://localhost'
  93. },
  94. {
  95. config: {
  96. displayType: 'string',
  97. value: 'http://localhost ',
  98. name: 'oozie.service.JPAService.jdbc.url'
  99. },
  100. e: 'http://localhost'
  101. },
  102. {
  103. config: {
  104. displayType: 'custom',
  105. value: ' custom value '
  106. },
  107. e: ' custom value'
  108. },
  109. {
  110. config: {
  111. displayType: 'componentHosts',
  112. value: ['host1.com', 'host2.com']
  113. },
  114. e: ['host1.com', 'host2.com']
  115. }
  116. ];
  117. tests.forEach(function(test) {
  118. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  119. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  120. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  121. });
  122. });
  123. });
  124. describe('#preDefinedConfigFile', function() {
  125. before(function() {
  126. setups.setupStackVersion(this, 'BIGTOP-0.8');
  127. });
  128. it('bigtop site properties should be ok.', function() {
  129. var bigtopSiteProperties = App.config.preDefinedConfigFile('BIGTOP', 'site_properties');
  130. expect(bigtopSiteProperties).to.be.ok;
  131. });
  132. it('a non-existing file should not be ok.', function () {
  133. var notExistingSiteProperty = App.config.preDefinedConfigFile('notExisting');
  134. expect(notExistingSiteProperty).to.not.be.ok;
  135. });
  136. after(function() {
  137. setups.restoreStackVersion(this);
  138. });
  139. });
  140. describe('#preDefinedSiteProperties-bigtop', function () {
  141. before(function() {
  142. setups.setupStackVersion(this, 'BIGTOP-0.8');
  143. });
  144. it('bigtop should use New PostgreSQL Database as its default hive metastore database', function () {
  145. App.StackService.createRecord({serviceName: 'HIVE'});
  146. expect(App.config.get('preDefinedSiteProperties').findProperty('recommendedValue', 'New PostgreSQL Database')).to.be.ok;
  147. });
  148. after(function() {
  149. setups.restoreStackVersion(this);
  150. });
  151. });
  152. describe('#generateConfigPropertiesByName', function() {
  153. var tests = [
  154. {
  155. names: ['property_1', 'property_2'],
  156. properties: undefined,
  157. e: {
  158. keys: ['name']
  159. },
  160. m: 'Should generate base property object without additional fields'
  161. },
  162. {
  163. names: ['property_1', 'property_2'],
  164. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  165. e: {
  166. keys: ['name', 'category', 'serviceName']
  167. },
  168. m: 'Should generate base property object without additional fields'
  169. }
  170. ];
  171. tests.forEach(function(test) {
  172. it(test.m, function() {
  173. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  174. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  175. return Em.keys(property);
  176. }).reduce(function(p, c) {
  177. return p.concat(c);
  178. }).uniq()).to.eql(test.e.keys);
  179. });
  180. });
  181. });
  182. describe('#setPreDefinedServiceConfigs', function() {
  183. beforeEach(function() {
  184. sinon.stub(App.StackService, 'find', function() {
  185. return [
  186. Em.Object.create({
  187. id: 'HDFS',
  188. serviceName: 'HDFS',
  189. configTypes: {
  190. 'hadoop-env': {},
  191. 'hdfs-site': {}
  192. }
  193. }),
  194. Em.Object.create({
  195. id: 'OOZIE',
  196. serviceName: 'OOZIE',
  197. configTypes: {
  198. 'oozie-env': {},
  199. 'oozie-site': {}
  200. }
  201. })
  202. ];
  203. });
  204. App.config.setPreDefinedServiceConfigs(true);
  205. });
  206. afterEach(function() {
  207. App.StackService.find.restore();
  208. });
  209. it('should include service MISC', function() {
  210. expect(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC')).to.be.ok;
  211. });
  212. it('should include -env config types according to stack services', function() {
  213. var miscCategory = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC');
  214. expect(Em.keys(miscCategory.get('configTypes'))).to.eql(['cluster-env', 'hadoop-env', 'oozie-env']);
  215. });
  216. });
  217. describe('#isManagedMySQLForHiveAllowed', function () {
  218. var cases = [
  219. {
  220. osFamily: 'redhat5',
  221. expected: false
  222. },
  223. {
  224. osFamily: 'redhat6',
  225. expected: true
  226. },
  227. {
  228. osFamily: 'suse11',
  229. expected: false
  230. }
  231. ],
  232. title = 'should be {0} for {1}';
  233. cases.forEach(function (item) {
  234. it(title.format(item.expected, item.osFamily), function () {
  235. expect(App.config.isManagedMySQLForHiveAllowed(item.osFamily)).to.equal(item.expected);
  236. });
  237. });
  238. });
  239. describe('#shouldSupportFinal', function () {
  240. var cases = [
  241. {
  242. shouldSupportFinal: false,
  243. title: 'no service name specified'
  244. },
  245. {
  246. serviceName: 's0',
  247. shouldSupportFinal: false,
  248. title: 'no filename specified'
  249. },
  250. {
  251. serviceName: 'MISC',
  252. shouldSupportFinal: false,
  253. title: 'MISC'
  254. },
  255. {
  256. serviceName: 's0',
  257. filename: 's0-site',
  258. shouldSupportFinal: true,
  259. title: 'final attribute supported'
  260. },
  261. {
  262. serviceName: 's0',
  263. filename: 's0-env',
  264. shouldSupportFinal: false,
  265. title: 'final attribute not supported'
  266. },
  267. {
  268. serviceName: 'Cluster',
  269. filename: 'krb5-conf.xml',
  270. shouldSupportFinal: false,
  271. title: 'kerberos descriptor identities don\'t support final'
  272. }
  273. ];
  274. beforeEach(function () {
  275. sinon.stub(App.StackService, 'find').returns([
  276. {
  277. serviceName: 's0'
  278. }
  279. ]);
  280. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  281. supportsFinal: ['s0-site']
  282. });
  283. });
  284. afterEach(function () {
  285. App.StackService.find.restore();
  286. App.config.getConfigTypesInfoFromService.restore();
  287. });
  288. cases.forEach(function (item) {
  289. it(item.title, function () {
  290. expect(App.config.shouldSupportFinal(item.serviceName, item.filename)).to.equal(item.shouldSupportFinal);
  291. });
  292. });
  293. });
  294. describe('#shouldSupportAddingForbidden', function () {
  295. var cases = [
  296. {
  297. shouldSupportAddingForbidden: false,
  298. title: 'no service name specified'
  299. },
  300. {
  301. serviceName: 's0',
  302. shouldSupportAddingForbidden: false,
  303. title: 'no filename specified'
  304. },
  305. {
  306. serviceName: 'MISC',
  307. shouldSupportAddingForbidden: false,
  308. title: 'MISC'
  309. },
  310. {
  311. serviceName: 's0',
  312. filename: 's0-site',
  313. shouldSupportAddingForbidden: true,
  314. title: 'adding forbidden supported'
  315. },
  316. {
  317. serviceName: 's0',
  318. filename: 's0-properties',
  319. shouldSupportAddingForbidden: false,
  320. title: 'adding forbidden not supported'
  321. }
  322. ];
  323. beforeEach(function () {
  324. sinon.stub(App.StackService, 'find').returns([
  325. Em.Object.create({
  326. serviceName: 's0',
  327. configTypes: {
  328. 's0-size': {},
  329. 's0-properties': {}
  330. }
  331. })
  332. ]);
  333. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  334. supportsAddingForbidden: ['s0-site']
  335. });
  336. });
  337. afterEach(function () {
  338. App.StackService.find.restore();
  339. App.config.getConfigTypesInfoFromService.restore();
  340. });
  341. cases.forEach(function (item) {
  342. it(item.title, function () {
  343. expect(App.config.shouldSupportAddingForbidden(item.serviceName, item.filename)).to.equal(item.shouldSupportAddingForbidden);
  344. });
  345. });
  346. });
  347. describe('#removeRangerConfigs', function () {
  348. it('should remove ranger configs and categories', function () {
  349. var configs = [
  350. Em.Object.create({
  351. configs: [
  352. Em.Object.create({filename: 'filename'}),
  353. Em.Object.create({filename: 'ranger-filename'})
  354. ],
  355. configCategories: [
  356. Em.Object.create({name: 'ranger-name'}),
  357. Em.Object.create({name: 'name'}),
  358. Em.Object.create({name: 'also-ranger-name'})
  359. ]
  360. })
  361. ];
  362. App.config.removeRangerConfigs(configs);
  363. expect(configs).eql(
  364. [
  365. Em.Object.create({
  366. configs: [
  367. Em.Object.create({filename: 'filename'})
  368. ],
  369. configCategories: [
  370. Em.Object.create({name: 'name'})
  371. ]
  372. })
  373. ]
  374. );
  375. });
  376. });
  377. describe("#createOverride", function() {
  378. var template = {
  379. name: "p1",
  380. filename: "f1",
  381. value: "v1",
  382. recommendedValue: "rv1",
  383. savedValue: "sv1",
  384. isFinal: true,
  385. recommendedIsFinal: false,
  386. savedIsFinal: true
  387. };
  388. var configProperty = App.ServiceConfigProperty.create(template);
  389. var group = Em.Object.create({name: "group1"});
  390. Object.keys(template).forEach(function (key) {
  391. it(key, function () {
  392. var override = App.config.createOverride(configProperty, {}, group);
  393. expect(override.get(key)).to.equal(template[key]);
  394. });
  395. });
  396. describe('overrides some values that should be different for override', function() {
  397. var override;
  398. beforeEach(function () {
  399. override = App.config.createOverride(configProperty, {}, group);
  400. });
  401. it('isOriginalSCP is false', function () {
  402. expect(override.get('isOriginalSCP')).to.be.false;
  403. });
  404. it('overrides is null', function () {
  405. expect(override.get('overrides')).to.be.null;
  406. });
  407. it('group is valid', function () {
  408. expect(override.get('group')).to.eql(group);
  409. });
  410. it('parentSCP is valid', function () {
  411. expect(override.get('parentSCP')).to.eql(configProperty);
  412. });
  413. });
  414. var overriddenTemplate = {
  415. value: "v2",
  416. recommendedValue: "rv2",
  417. savedValue: "sv2",
  418. isFinal: true,
  419. recommendedIsFinal: false,
  420. savedIsFinal: true
  421. };
  422. Object.keys(overriddenTemplate).forEach(function (key) {
  423. it('overrides some specific values `' + key + '`', function () {
  424. var override = App.config.createOverride(configProperty, overriddenTemplate, group);
  425. expect(override.get(key)).to.equal(overriddenTemplate[key]);
  426. });
  427. });
  428. it('throws error due to undefined configGroup', function() {
  429. expect(App.config.createOverride.bind(App.config, configProperty, {}, null)).to.throw(Error, 'configGroup can\' be null');
  430. });
  431. it('throws error due to undefined originalSCP', function() {
  432. expect(App.config.createOverride.bind(App.config, null, {}, group)).to.throw(Error, 'serviceConfigProperty can\' be null');
  433. });
  434. describe('updates originalSCP object ', function() {
  435. var overridenTemplate2;
  436. var override;
  437. beforeEach(function () {
  438. configProperty.set('overrides', null);
  439. configProperty.set('overrideValues', []);
  440. configProperty.set('overrideIsFinalValues', []);
  441. overridenTemplate2 = {
  442. value: "v12",
  443. recommendedValue: "rv12",
  444. savedValue: "sv12",
  445. isFinal: true,
  446. recommendedIsFinal: false,
  447. savedIsFinal: false
  448. };
  449. override = App.config.createOverride(configProperty, overridenTemplate2, group);
  450. });
  451. it('overrides.0 is valid', function () {
  452. expect(configProperty.get('overrides')[0]).to.be.eql(override);
  453. });
  454. it('overrideValues is valid', function () {
  455. expect(configProperty.get('overrideValues')).to.be.eql([overridenTemplate2.value]);
  456. });
  457. it('overrideIsFinalValues is valid', function () {
  458. expect(configProperty.get('overrideIsFinalValues')).to.be.eql([overridenTemplate2.isFinal]);
  459. });
  460. });
  461. });
  462. describe('#getIsSecure', function() {
  463. var secureConfigs = App.config.get('secureConfigs');
  464. before(function() {
  465. App.config.set('secureConfigs', [{name: 'secureConfig'}]);
  466. });
  467. after(function() {
  468. App.config.set('secureConfigs', secureConfigs);
  469. });
  470. it('config is secure', function() {
  471. expect(App.config.getIsSecure('secureConfig')).to.equal(true);
  472. });
  473. it('config is not secure', function() {
  474. expect(App.config.getIsSecure('NotSecureConfig')).to.equal(false);
  475. });
  476. });
  477. describe('#getDefaultCategory', function() {
  478. it('returns custom category', function() {
  479. expect(App.config.getDefaultCategory(null, 'filename.xml')).to.equal('Custom filename');
  480. });
  481. it('returns advanced category', function() {
  482. expect(App.config.getDefaultCategory(Em.Object.create, 'filename.xml')).to.equal('Advanced filename');
  483. });
  484. });
  485. describe('#getDefaultDisplayType', function() {
  486. it('returns singleLine displayType', function() {
  487. expect(App.config.getDefaultDisplayType('v1')).to.equal('string');
  488. });
  489. it('returns multiLine displayType', function() {
  490. expect(App.config.getDefaultDisplayType('v1\nv2')).to.equal('multiLine');
  491. });
  492. });
  493. describe('#formatValue', function() {
  494. it('formatValue for componentHosts', function () {
  495. var serviceConfigProperty = Em.Object.create({'displayType': 'componentHosts', value: "['h1','h2']"});
  496. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.eql(['h1','h2']);
  497. });
  498. it('formatValue for int', function () {
  499. var serviceConfigProperty = Em.Object.create({'displayType': 'int', value: '4.0'});
  500. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('4');
  501. });
  502. it('formatValue for int with m', function () {
  503. var serviceConfigProperty = Em.Object.create({'displayType': 'int', value: '4m'});
  504. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('4');
  505. });
  506. it('formatValue for float', function () {
  507. var serviceConfigProperty = Em.Object.create({'displayType': 'float', value: '0.40'});
  508. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('0.4');
  509. });
  510. it('formatValue for kdc_type', function () {
  511. var serviceConfigProperty = Em.Object.create({'name': 'kdc_type', value: 'mit-kdc'});
  512. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal(Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
  513. });
  514. it('don\'t format value', function () {
  515. var serviceConfigProperty = Em.Object.create({'name': 'any', displayType: 'any', value: 'any'});
  516. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('any');
  517. });
  518. });
  519. describe('#getPropertyIfExists', function() {
  520. [
  521. {
  522. propertyName: 'someProperty',
  523. defaultValue: 'default',
  524. firstObject: { someProperty: '1' },
  525. secondObject: { someProperty: '2' },
  526. res: '1',
  527. m: 'use value from first object'
  528. },
  529. {
  530. propertyName: 'someProperty',
  531. defaultValue: 'default',
  532. firstObject: { someOtherProperty: '1' },
  533. secondObject: { someProperty: '2' },
  534. res: '2',
  535. m: 'use value from second object'
  536. },
  537. {
  538. propertyName: 'someProperty',
  539. defaultValue: 'default',
  540. firstObject: { someOtherProperty: '1' },
  541. secondObject: { someOtherProperty: '2' },
  542. res: 'default',
  543. m: 'use default value'
  544. },
  545. {
  546. propertyName: 'someProperty',
  547. defaultValue: 'default',
  548. res: 'default',
  549. m: 'use default value'
  550. },
  551. {
  552. propertyName: 'someProperty',
  553. defaultValue: true,
  554. firstObject: { someProperty: false },
  555. secondObject: { someProperty: true },
  556. res: false,
  557. m: 'use value from first object, check booleans'
  558. },
  559. {
  560. propertyName: 'someProperty',
  561. defaultValue: true,
  562. firstObject: { someProperty: 0 },
  563. secondObject: { someProperty: 1 },
  564. res: 0,
  565. m: 'use value from first object, check 0'
  566. },
  567. {
  568. propertyName: 'someProperty',
  569. defaultValue: true,
  570. firstObject: { someProperty: '' },
  571. secondObject: { someProperty: '1' },
  572. res: '',
  573. m: 'use value from first object, check empty string'
  574. }
  575. ].forEach(function (t) {
  576. it(t.m, function () {
  577. expect(App.config.getPropertyIfExists(t.propertyName, t.defaultValue, t.firstObject, t.secondObject)).to.equal(t.res);
  578. })
  579. });
  580. });
  581. describe('#createDefaultConfig', function() {
  582. before(function() {
  583. sinon.stub(App.config, 'getDefaultDisplayType', function() {
  584. return 'pDisplayType';
  585. });
  586. sinon.stub(App.config, 'getDefaultCategory', function() {
  587. return 'pCategory';
  588. });
  589. sinon.stub(App.config, 'getIsSecure', function() {
  590. return false;
  591. });
  592. sinon.stub(App.config, 'shouldSupportFinal', function() {
  593. return true;
  594. });
  595. sinon.stub(App.config, 'get', function(param) {
  596. if (param === 'serviceByConfigTypeMap') {
  597. return { 'pFileName': Em.Object.create({serviceName: 'pServiceName' }) };
  598. }
  599. return Em.get(App.config, param);
  600. });
  601. });
  602. after(function() {
  603. App.config.getDefaultDisplayType.restore();
  604. App.config.getDefaultCategory.restore();
  605. App.config.getIsSecure.restore();
  606. App.config.shouldSupportFinal.restore();
  607. App.config.get.restore();
  608. });
  609. var res = {
  610. /** core properties **/
  611. id: 'pName__pFileName',
  612. name: 'pName',
  613. filename: 'pFileName.xml',
  614. value: '',
  615. savedValue: null,
  616. isFinal: false,
  617. savedIsFinal: null,
  618. /** UI and Stack properties **/
  619. recommendedValue: null,
  620. recommendedIsFinal: null,
  621. supportsFinal: true,
  622. supportsAddingForbidden: false,
  623. serviceName: 'pServiceName',
  624. displayName: 'pName',
  625. displayType: 'pDisplayType',
  626. description: '',
  627. category: 'pCategory',
  628. isSecureConfig: false,
  629. showLabel: true,
  630. isVisible: true,
  631. isUserProperty: false,
  632. isRequired: true,
  633. group: null,
  634. isRequiredByAgent: true,
  635. isReconfigurable: true,
  636. unit: null,
  637. hasInitialValue: false,
  638. isOverridable: true,
  639. index: Infinity,
  640. dependentConfigPattern: null,
  641. options: null,
  642. radioName: null,
  643. widgetType: null
  644. };
  645. it('create default config object', function () {
  646. expect(App.config.createDefaultConfig('pName', 'pFileName', true)).to.eql(res);
  647. });
  648. it('getDefaultDisplayType is called', function() {
  649. expect(App.config.getDefaultDisplayType.called).to.be.true;
  650. });
  651. it('getDefaultCategory is called with correct arguments', function() {
  652. expect(App.config.getDefaultCategory.calledWith(true, 'pFileName')).to.be.true;
  653. });
  654. it('getIsSecure is called with correct arguments', function() {
  655. expect(App.config.getIsSecure.calledWith('pName')).to.be.true;
  656. });
  657. it('shouldSupportFinal is called with correct arguments', function() {
  658. expect(App.config.shouldSupportFinal.calledWith('pServiceName', 'pFileName')).to.be.true;
  659. });
  660. });
  661. describe('#mergeStackConfigsWithUI', function() {
  662. beforeEach(function() {
  663. sinon.stub(App.config, 'getPropertyIfExists', function(key, value) {return 'res_' + value});
  664. });
  665. afterEach(function() {
  666. App.config.getPropertyIfExists.restore();
  667. });
  668. var template = {
  669. name: 'pName',
  670. filename: 'pFileName',
  671. value: 'pValue',
  672. savedValue: 'pValue',
  673. isFinal: true,
  674. savedIsFinal: true,
  675. serviceName: 'pServiceName',
  676. displayName: 'pDisplayName',
  677. displayType: 'pDisplayType',
  678. category: 'pCategory'
  679. };
  680. var result = {
  681. name: 'pName',
  682. filename: 'pFileName',
  683. value: 'pValue',
  684. savedValue: 'pValue',
  685. isFinal: true,
  686. savedIsFinal: true,
  687. serviceName: 'res_pServiceName',
  688. displayName: 'res_pDisplayName',
  689. displayType: 'res_pDisplayType',
  690. category: 'res_pCategory'
  691. };
  692. it('called generate property object', function () {
  693. expect(App.config.mergeStaticProperties(template, {}, {})).to.eql(result);
  694. });
  695. });
  696. describe('#updateHostsListValue', function() {
  697. var tests = [
  698. {
  699. siteConfigs: {
  700. 'hadoop.registry.zk.quorum': 'host1,host2'
  701. },
  702. propertyName: 'hadoop.registry.zk.quorum',
  703. hostsList: 'host1',
  704. e: 'host1'
  705. },
  706. {
  707. siteConfigs: {
  708. 'hadoop.registry.zk.quorum': 'host1:10,host2:10'
  709. },
  710. propertyName: 'hadoop.registry.zk.quorum',
  711. hostsList: 'host2:10,host1:10',
  712. e: 'host1:10,host2:10'
  713. },
  714. {
  715. siteConfigs: {
  716. 'hadoop.registry.zk.quorum': 'host1:10,host2:10,host3:10'
  717. },
  718. propertyName: 'hadoop.registry.zk.quorum',
  719. hostsList: 'host2:10,host1:10',
  720. e: 'host2:10,host1:10'
  721. },
  722. {
  723. siteConfigs: {
  724. 'hadoop.registry.zk.quorum': 'host1:10,host2:10,host3:10'
  725. },
  726. propertyName: 'hadoop.registry.zk.quorum',
  727. hostsList: 'host2:10,host1:10,host3:10,host4:11',
  728. e: 'host2:10,host1:10,host3:10,host4:11'
  729. },
  730. {
  731. siteConfigs: {
  732. 'hive.zookeeper.quorum': 'host1'
  733. },
  734. propertyName: 'some.new.property',
  735. hostsList: 'host2,host1:10',
  736. e: 'host2,host1:10'
  737. }
  738. ];
  739. tests.forEach(function(test) {
  740. it('ZK located on {0}, current prop value is "{1}" "{2}" value should be "{3}"'.format(test.hostsList, ''+test.siteConfigs[test.propertyName], test.propertyName, test.e), function() {
  741. var result = App.config.updateHostsListValue(test.siteConfigs, test.propertyName, test.hostsList);
  742. expect(result).to.be.eql(test.e);
  743. expect(test.siteConfigs[test.propertyName]).to.be.eql(test.e);
  744. });
  745. });
  746. });
  747. describe('#createHostNameProperty', function() {
  748. it('create host property', function() {
  749. expect(App.config.createHostNameProperty('service1', 'component1', ['host1'], Em.Object.create({
  750. isMultipleAllowed: false,
  751. displayName: 'display name'
  752. }))).to.eql({
  753. "name": 'component1_host',
  754. "displayName": 'display name host',
  755. "value": ['host1'],
  756. "recommendedValue": ['host1'],
  757. "description": "The host that has been assigned to run display name",
  758. "displayType": "componentHost",
  759. "isOverridable": false,
  760. "isRequiredByAgent": false,
  761. "serviceName": 'service1',
  762. "filename": "service1-site.xml",
  763. "category": 'component1',
  764. "index": 0
  765. })
  766. });
  767. it('create hosts property', function() {
  768. expect(App.config.createHostNameProperty('service1', 'component1', ['host1'], Em.Object.create({
  769. isMultipleAllowed: true,
  770. displayName: 'display name'
  771. }))).to.eql({
  772. "name": 'component1_hosts',
  773. "displayName": 'display name host',
  774. "value": ['host1'],
  775. "recommendedValue": ['host1'],
  776. "description": "The hosts that has been assigned to run display name",
  777. "displayType": "componentHosts",
  778. "isOverridable": false,
  779. "isRequiredByAgent": false,
  780. "serviceName": 'service1',
  781. "filename": "service1-site.xml",
  782. "category": 'component1',
  783. "index": 0
  784. })
  785. });
  786. });
  787. describe("#truncateGroupName()", function() {
  788. it("name is empty", function() {
  789. expect(App.config.truncateGroupName('')).to.be.empty;
  790. });
  791. it("name has less than max chars", function() {
  792. expect(App.config.truncateGroupName('group1')).to.equal('group1');
  793. });
  794. it("name has more than max chars", function() {
  795. expect(App.config.truncateGroupName('group_has_more_than_max_characters')).to.equal('group_has...haracters');
  796. });
  797. });
  798. });