service_config_property_test.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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('models/configs/objects/service_config_category');
  20. require('models/configs/objects/service_config_property');
  21. var serviceConfigProperty,
  22. serviceConfigPropertyInit,
  23. configsData = [
  24. Ember.Object.create({
  25. category: 'c0',
  26. overrides: [
  27. {
  28. error: true,
  29. errorMessage: 'error'
  30. },
  31. {
  32. error: true
  33. },
  34. {}
  35. ]
  36. }),
  37. Ember.Object.create({
  38. category: 'c1',
  39. isValid: false,
  40. isVisible: true
  41. }),
  42. Ember.Object.create({
  43. category: 'c0',
  44. isValid: true,
  45. isVisible: true
  46. }),
  47. Ember.Object.create({
  48. category: 'c1',
  49. isValid: false,
  50. isVisible: false
  51. })
  52. ],
  53. components = [
  54. {
  55. name: 'NameNode',
  56. master: true
  57. },
  58. {
  59. name: 'SNameNode',
  60. master: true
  61. },
  62. {
  63. name: 'JobTracker',
  64. master: true
  65. },
  66. {
  67. name: 'HBase Master',
  68. master: true
  69. },
  70. {
  71. name: 'Oozie Master',
  72. master: true
  73. },
  74. {
  75. name: 'Hive Metastore',
  76. master: true
  77. },
  78. {
  79. name: 'WebHCat Server',
  80. master: true
  81. },
  82. {
  83. name: 'ZooKeeper Server',
  84. master: true
  85. },
  86. {
  87. name: 'Ganglia',
  88. master: true
  89. },
  90. {
  91. name: 'DataNode',
  92. slave: true
  93. },
  94. {
  95. name: 'TaskTracker',
  96. slave: true
  97. },
  98. {
  99. name: 'RegionServer',
  100. slave: true
  101. }
  102. ],
  103. overridableFalseData = [
  104. {
  105. isOverridable: false
  106. },
  107. {
  108. isEditable: false,
  109. overrides: configsData[0].overrides
  110. },
  111. {
  112. displayType: 'componentHost'
  113. }
  114. ],
  115. overridableTrueData = [
  116. {
  117. isOverridable: true,
  118. isEditable: true
  119. }, {
  120. isOverridable: true,
  121. overrides: []
  122. },
  123. {
  124. isOverridable: true
  125. }
  126. ],
  127. overriddenFalseData = [
  128. {
  129. overrides: null,
  130. isOriginalSCP: true
  131. },
  132. {
  133. overrides: [],
  134. isOriginalSCP: true
  135. }
  136. ],
  137. overriddenTrueData = [
  138. {
  139. overrides: configsData[0].overrides
  140. },
  141. {
  142. isOriginalSCP: false
  143. }
  144. ],
  145. removableFalseData = [
  146. {
  147. isEditable: false
  148. },
  149. {
  150. hasOverrides: true
  151. },
  152. {
  153. isUserProperty: false,
  154. isOriginalSCP: true
  155. }
  156. ],
  157. removableTrueData = [
  158. {
  159. isEditable: true,
  160. hasOverrides: false,
  161. isUserProperty: true
  162. },
  163. {
  164. isEditable: true,
  165. hasOverrides: false,
  166. isOriginalSCP: false
  167. }
  168. ],
  169. initPropertyData = [
  170. {
  171. initial: {
  172. displayType: 'password',
  173. value: 'value',
  174. recommendedValue: 'recommended'
  175. },
  176. result: {
  177. retypedPassword: 'value',
  178. recommendedValue: ''
  179. }
  180. },
  181. {
  182. initial: {
  183. value: '',
  184. savedValue: 'default',
  185. recommendedValue: 'recommended'
  186. },
  187. result: {
  188. value: '',
  189. recommendedValue: 'recommended'
  190. }
  191. },
  192. {
  193. initial: {
  194. value: null,
  195. savedValue: 'default',
  196. recommendedValue: 'recommended'
  197. },
  198. result: {
  199. value: 'default',
  200. recommendedValue: 'recommended'
  201. }
  202. }
  203. ],
  204. notDefaultFalseData = [
  205. {
  206. isEditable: false
  207. },
  208. {
  209. savedValue: null
  210. },
  211. {
  212. value: 'value',
  213. savedValue: 'value'
  214. }
  215. ],
  216. notDefaultTrueData = {
  217. isEditable: true,
  218. value: 'value',
  219. savedValue: 'default'
  220. },
  221. types = ['componentHost', 'componentHosts', 'radio button'],
  222. classCases = [
  223. {
  224. initial: {
  225. displayType: 'checkbox'
  226. },
  227. viewClass: App.ServiceConfigCheckbox
  228. },
  229. {
  230. initial: {
  231. displayType: 'checkbox',
  232. dependentConfigPattern: 'somPattern'
  233. },
  234. viewClass: App.ServiceConfigCheckboxWithDependencies
  235. },
  236. {
  237. initial: {
  238. displayType: 'password'
  239. },
  240. viewClass: App.ServiceConfigPasswordField
  241. },
  242. {
  243. initial: {
  244. displayType: 'combobox'
  245. },
  246. viewClass: App.ServiceConfigComboBox
  247. },
  248. {
  249. initial: {
  250. displayType: 'radio button'
  251. },
  252. viewClass: App.ServiceConfigRadioButtons
  253. },
  254. {
  255. initial: {
  256. displayType: 'directories'
  257. },
  258. viewClass: App.ServiceConfigTextArea
  259. },
  260. {
  261. initial: {
  262. displayType: 'content'
  263. },
  264. viewClass: App.ServiceConfigTextAreaContent
  265. },
  266. {
  267. initial: {
  268. displayType: 'multiLine'
  269. },
  270. viewClass: App.ServiceConfigTextArea
  271. },
  272. {
  273. initial: {
  274. displayType: 'custom'
  275. },
  276. viewClass: App.ServiceConfigBigTextArea
  277. },
  278. {
  279. initial: {
  280. displayType: 'componentHost'
  281. },
  282. viewClass: App.ServiceConfigMasterHostView
  283. },
  284. {
  285. initial: {
  286. displayType: 'componentHosts'
  287. },
  288. viewClass: App.ServiceConfigComponentHostsView
  289. },
  290. {
  291. initial: {
  292. displayType: 'componentHosts'
  293. },
  294. viewClass: App.ServiceConfigComponentHostsView
  295. },
  296. {
  297. initial: {
  298. unit: true,
  299. displayType: 'type'
  300. },
  301. viewClass: App.ServiceConfigTextFieldWithUnit
  302. },
  303. {
  304. initial: {
  305. unit: false,
  306. displayType: 'type'
  307. },
  308. viewClass: App.ServiceConfigTextField
  309. },
  310. {
  311. initial: {
  312. unit: false,
  313. displayType: 'supportTextConnection'
  314. },
  315. viewClass: App.checkConnectionView
  316. }
  317. ];
  318. function getProperty() {
  319. return App.ServiceConfigProperty.create();
  320. }
  321. describe('App.ServiceConfigProperty', function () {
  322. beforeEach(function () {
  323. serviceConfigProperty = getProperty();
  324. });
  325. App.TestAliases.testAsComputedFirstNotBlank(getProperty(), 'placeholder', ['placeholderText', 'savedValue']);
  326. describe('#overrideErrorTrigger', function () {
  327. it('should be an increment', function () {
  328. serviceConfigProperty.set('overrides', configsData[0].overrides);
  329. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(1);
  330. serviceConfigProperty.set('overrides', []);
  331. expect(serviceConfigProperty.get('overrideErrorTrigger')).to.equal(2);
  332. });
  333. });
  334. describe('#isPropertyOverridable', function () {
  335. overridableFalseData.forEach(function (item) {
  336. it('should be false', function () {
  337. Em.keys(item).forEach(function (prop) {
  338. serviceConfigProperty.set(prop, item[prop]);
  339. });
  340. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.false;
  341. });
  342. });
  343. overridableTrueData.forEach(function (item) {
  344. it('should be true', function () {
  345. Em.keys(item).forEach(function (prop) {
  346. serviceConfigProperty.set(prop, item[prop]);
  347. });
  348. expect(serviceConfigProperty.get('isPropertyOverridable')).to.be.true;
  349. });
  350. });
  351. });
  352. describe('#isOverridden', function () {
  353. overriddenFalseData.forEach(function (item) {
  354. it('should be false', function () {
  355. Em.keys(item).forEach(function (prop) {
  356. serviceConfigProperty.set(prop, item[prop]);
  357. });
  358. expect(serviceConfigProperty.get('isOverridden')).to.be.false;
  359. });
  360. });
  361. overriddenTrueData.forEach(function (item) {
  362. it('should be true', function () {
  363. Em.keys(item).forEach(function (prop) {
  364. serviceConfigProperty.set(prop, item[prop]);
  365. });
  366. expect(serviceConfigProperty.get('isOverridden')).to.be.true;
  367. });
  368. });
  369. });
  370. describe('#isRemovable', function () {
  371. removableFalseData.forEach(function (item) {
  372. it('should be false', function () {
  373. Em.keys(item).forEach(function (prop) {
  374. serviceConfigProperty.set(prop, item[prop]);
  375. });
  376. expect(serviceConfigProperty.get('isRemovable')).to.be.false;
  377. });
  378. });
  379. removableTrueData.forEach(function (item) {
  380. it('should be true', function () {
  381. Em.keys(item).forEach(function (prop) {
  382. serviceConfigProperty.set(prop, item[prop]);
  383. });
  384. expect(serviceConfigProperty.get('isRemovable')).to.be.true;
  385. });
  386. });
  387. });
  388. describe('#init', function () {
  389. initPropertyData.forEach(function (item) {
  390. it('should set initial data', function () {
  391. serviceConfigPropertyInit = App.ServiceConfigProperty.create(item.initial);
  392. Em.keys(item.result).forEach(function (prop) {
  393. expect(serviceConfigPropertyInit.get(prop)).to.equal(item.result[prop]);
  394. });
  395. });
  396. });
  397. });
  398. describe('#isNotDefaultValue', function () {
  399. notDefaultFalseData.forEach(function (item) {
  400. it('should be false', function () {
  401. Em.keys(item).forEach(function (prop) {
  402. serviceConfigProperty.set(prop, item[prop]);
  403. });
  404. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.false;
  405. });
  406. });
  407. it('should be true', function () {
  408. Em.keys(notDefaultTrueData).forEach(function (prop) {
  409. serviceConfigProperty.set(prop, notDefaultTrueData[prop]);
  410. });
  411. expect(serviceConfigProperty.get('isNotDefaultValue')).to.be.true;
  412. });
  413. });
  414. describe('#cantBeUndone', function () {
  415. types.forEach(function (item) {
  416. it('should be true', function () {
  417. serviceConfigProperty.set('displayType', item);
  418. expect(serviceConfigProperty.get('cantBeUndone')).to.be.true;
  419. });
  420. });
  421. it('should be false', function () {
  422. serviceConfigProperty.set('displayType', 'type');
  423. expect(serviceConfigProperty.get('cantBeUndone')).to.be.false;
  424. });
  425. });
  426. describe('#isValid', function () {
  427. it('should be true', function () {
  428. serviceConfigProperty.set('errorMessage', '');
  429. expect(serviceConfigProperty.get('isValid')).to.be.true;
  430. });
  431. it('should be false', function () {
  432. serviceConfigProperty.set('errorMessage', 'message');
  433. expect(serviceConfigProperty.get('isValid')).to.be.false;
  434. });
  435. });
  436. describe('#viewClass', function () {
  437. classCases.forEach(function (item) {
  438. it ('should be ' + item.viewClass, function () {
  439. Em.keys(item.initial).forEach(function (prop) {
  440. serviceConfigProperty.set(prop, item.initial[prop]);
  441. });
  442. expect(serviceConfigProperty.get('viewClass')).to.eql(item.viewClass);
  443. });
  444. });
  445. });
  446. describe('#validate', function () {
  447. it('not required', function () {
  448. serviceConfigProperty.setProperties({
  449. isRequired: false,
  450. value: ''
  451. });
  452. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  453. expect(serviceConfigProperty.get('error')).to.be.false;
  454. });
  455. it('should validate', function () {
  456. serviceConfigProperty.setProperties({
  457. isRequired: true,
  458. value: 'value'
  459. });
  460. expect(serviceConfigProperty.get('errorMessage')).to.be.empty;
  461. expect(serviceConfigProperty.get('error')).to.be.false;
  462. });
  463. it('should fail', function () {
  464. serviceConfigProperty.setProperties({
  465. isRequired: true,
  466. value: 'value'
  467. });
  468. serviceConfigProperty.set('value', '');
  469. expect(serviceConfigProperty.get('errorMessage')).to.equal('This is required');
  470. expect(serviceConfigProperty.get('error')).to.be.true;
  471. });
  472. });
  473. describe('#overrideIsFinalValues', function () {
  474. it('should be defined as empty array', function () {
  475. expect(serviceConfigProperty.get('overrideIsFinalValues')).to.eql([]);
  476. });
  477. });
  478. describe('#updateDescription', function () {
  479. beforeEach(function () {
  480. serviceConfigProperty.setProperties({
  481. displayType: 'password',
  482. description: ''
  483. });
  484. });
  485. it('should add extra-message to the description for `password`-configs', function () {
  486. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  487. serviceConfigProperty.updateDescription();
  488. expect(serviceConfigProperty.get('description')).to.contain(extraMessage);
  489. });
  490. it('should not add extra-message to the description if it already contains it', function () {
  491. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  492. serviceConfigProperty.updateDescription();
  493. serviceConfigProperty.updateDescription();
  494. serviceConfigProperty.updateDescription();
  495. expect(serviceConfigProperty.get('description')).to.contain(extraMessage);
  496. var subd = serviceConfigProperty.get('description').replace(extraMessage, '');
  497. expect(subd).to.not.contain(extraMessage);
  498. });
  499. it('should add extra-message to the description if description is not defined', function () {
  500. serviceConfigProperty.set('description', undefined);
  501. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  502. serviceConfigProperty.updateDescription();
  503. expect(serviceConfigProperty.get('description')).to.contain(extraMessage);
  504. });
  505. });
  506. });