controls_view_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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('views/wizard/controls_view');
  20. describe('App.ServiceConfigRadioButtons', function () {
  21. describe('#didInsertElement', function () {
  22. var view = App.ServiceConfigRadioButtons.create({
  23. categoryConfigsAll: [],
  24. controller: Em.Object.create({
  25. wizardController: Em.Object.create({})
  26. }),
  27. serviceConfig: Em.Object.create({
  28. value: null
  29. })
  30. }),
  31. cases = [
  32. {
  33. wizardControllerName: 'addServiceController',
  34. serviceConfigValue: 'New MySQL Database',
  35. onOptionsChangeCalledTwice: true,
  36. handleDBConnectionPropertyCalledTwice: false,
  37. title: 'Add Service Wizard, New MySQL Database'
  38. },
  39. {
  40. wizardControllerName: 'addServiceController',
  41. serviceConfigValue: 'Existing MySQL Database',
  42. onOptionsChangeCalledTwice: false,
  43. handleDBConnectionPropertyCalledTwice: true,
  44. title: 'Add Service Wizard, Existing MySQL Database'
  45. },
  46. {
  47. wizardControllerName: 'installerController',
  48. serviceConfigValue: 'New MySQL Database',
  49. onOptionsChangeCalledTwice: true,
  50. handleDBConnectionPropertyCalledTwice: false,
  51. title: 'Install Wizard, New MySQL Database'
  52. },
  53. {
  54. wizardControllerName: 'installerController',
  55. serviceConfigValue: 'Existing MySQL Database',
  56. onOptionsChangeCalledTwice: false,
  57. handleDBConnectionPropertyCalledTwice: true,
  58. title: 'Install Wizard, Existing MySQL Database'
  59. },
  60. {
  61. wizardControllerName: null,
  62. serviceConfigValue: null,
  63. onOptionsChangeCalledTwice: false,
  64. handleDBConnectionPropertyCalledTwice: false,
  65. title: 'Service Configs Page'
  66. }
  67. ];
  68. beforeEach(function () {
  69. sinon.stub(view, 'onOptionsChange', Em.K);
  70. sinon.stub(view, 'handleDBConnectionProperty', Em.K);
  71. });
  72. afterEach(function () {
  73. view.onOptionsChange.restore();
  74. view.handleDBConnectionProperty.restore();
  75. });
  76. cases.forEach(function (item) {
  77. it(item.title, function () {
  78. view.set('controller.wizardController.name', item.wizardControllerName);
  79. view.set('serviceConfig.value', item.serviceConfigValue);
  80. view.didInsertElement();
  81. expect(view.onOptionsChange.calledTwice).to.equal(item.onOptionsChangeCalledTwice);
  82. expect(view.handleDBConnectionProperty.calledTwice).to.equal(item.handleDBConnectionPropertyCalledTwice);
  83. });
  84. });
  85. });
  86. describe('#databaseNameProperty', function () {
  87. var view = App.ServiceConfigRadioButtons.create({
  88. serviceConfig: Em.Object.create(),
  89. categoryConfigsAll: [
  90. {
  91. name: 'ambari.hive.db.schema.name',
  92. value: 'db0'
  93. },
  94. {
  95. name: 'sink.db.schema.name',
  96. value: 'db1'
  97. },
  98. {
  99. name: 'oozie.db.schema.name',
  100. value: 'db2'
  101. }
  102. ]
  103. }),
  104. cases = [
  105. {
  106. serviceName: 'HIVE',
  107. value: 'db0'
  108. },
  109. {
  110. serviceName: 'HDFS',
  111. value: 'db1'
  112. },
  113. {
  114. serviceName: 'OOZIE',
  115. value: 'db2'
  116. }
  117. ];
  118. cases.forEach(function (item) {
  119. it(item.serviceName, function () {
  120. view.set('serviceConfig.serviceName', item.serviceName);
  121. expect(view.get('databaseNameProperty.value')).to.equal(item.value);
  122. expect(view.get('databaseName')).to.equal(item.value);
  123. });
  124. });
  125. it('default case', function () {
  126. view.set('serviceConfig.serviceName', 'YARN');
  127. expect(view.get('databaseNameProperty')).to.be.null;
  128. expect(view.get('databaseName')).to.be.null;
  129. });
  130. });
  131. describe('#hostNameProperty', function () {
  132. var view = App.ServiceConfigRadioButtons.create({
  133. serviceConfig: Em.Object.create(),
  134. categoryConfigsAll: [
  135. {
  136. name: 'hive_ambari_host',
  137. value: 'h0'
  138. },
  139. {
  140. name: 'hive_existing_mysql_host',
  141. value: 'h1'
  142. },
  143. {
  144. name: 'hive_existing_postgresql_host',
  145. value: 'h2'
  146. },
  147. {
  148. name: 'hive_existing_oracle_host',
  149. value: 'h3'
  150. },
  151. {
  152. name: 'hive_existing_mssql_server_host',
  153. value: 'h4'
  154. },
  155. {
  156. name: 'hive_existing_mssql_server_2_host',
  157. value: 'h5'
  158. },
  159. {
  160. name: 'hive_hostname',
  161. value: 'h6'
  162. },
  163. {
  164. name: 'sink_existing_mssql_server_host',
  165. value: 'h7'
  166. },
  167. {
  168. name: 'sink_existing_mssql_server_2_host',
  169. value: 'h8'
  170. },
  171. {
  172. name: 'sink.dbservername',
  173. value: 'h9'
  174. },
  175. {
  176. name: 'oozie_ambari_host',
  177. value: 'h10'
  178. },
  179. {
  180. name: 'oozie_existing_mysql_host',
  181. value: 'h11'
  182. },
  183. {
  184. name: 'oozie_existing_postgresql_host',
  185. value: 'h12'
  186. },
  187. {
  188. name: 'oozie_existing_oracle_host',
  189. value: 'h13'
  190. },
  191. {
  192. name: 'oozie_existing_mssql_server_host',
  193. value: 'h14'
  194. },
  195. {
  196. name: 'oozie_existing_mssql_server_2_host',
  197. value: 'h15'
  198. },
  199. {
  200. name: 'oozie_hostname',
  201. value: 'h16'
  202. }
  203. ]
  204. }),
  205. cases = [
  206. {
  207. serviceName: 'HIVE',
  208. value: 'New MySQL Database',
  209. expected: 'h0'
  210. },
  211. {
  212. serviceName: 'HIVE',
  213. value: 'Existing MySQL Database',
  214. expected: 'h1'
  215. },
  216. {
  217. serviceName: 'HIVE',
  218. value: Em.I18n.t('services.service.config.hive.oozie.postgresql'),
  219. expected: 'h2'
  220. },
  221. {
  222. serviceName: 'HIVE',
  223. value: 'Existing Oracle Database',
  224. expected: 'h3'
  225. },
  226. {
  227. serviceName: 'HIVE',
  228. value: 'Existing MSSQL Server database with integrated authentication',
  229. expected: 'h4'
  230. },
  231. {
  232. serviceName: 'HIVE',
  233. value: 'Existing MSSQL Server database with sql auth',
  234. expected: 'h5'
  235. },
  236. {
  237. serviceName: 'HIVE',
  238. value: 'default case',
  239. expected: 'h6'
  240. },
  241. {
  242. serviceName: 'HDFS',
  243. value: 'Existing MSSQL Server database with integrated authentication',
  244. expected: 'h7'
  245. },
  246. {
  247. serviceName: 'HDFS',
  248. value: 'Existing MSSQL Server database with sql auth',
  249. expected: 'h8'
  250. },
  251. {
  252. serviceName: 'HDFS',
  253. value: 'default case',
  254. expected: 'h9'
  255. },
  256. {
  257. serviceName: 'OOZIE',
  258. value: 'New Derby Database',
  259. expected: 'h10'
  260. },
  261. {
  262. serviceName: 'OOZIE',
  263. value: 'Existing MySQL Database',
  264. expected: 'h11'
  265. },
  266. {
  267. serviceName: 'OOZIE',
  268. value: Em.I18n.t('services.service.config.hive.oozie.postgresql'),
  269. expected: 'h12'
  270. },
  271. {
  272. serviceName: 'OOZIE',
  273. value: 'Existing Oracle Database',
  274. expected: 'h13'
  275. },
  276. {
  277. serviceName: 'OOZIE',
  278. value: 'Existing MSSQL Server database with integrated authentication',
  279. expected: 'h14'
  280. },
  281. {
  282. serviceName: 'OOZIE',
  283. value: 'Existing MSSQL Server database with sql auth',
  284. expected: 'h15'
  285. },
  286. {
  287. serviceName: 'OOZIE',
  288. value: 'default case',
  289. expected: 'h16'
  290. }
  291. ];
  292. before(function () {
  293. sinon.stub(view, 'handleDBConnectionProperty', Em.K);
  294. });
  295. after(function () {
  296. view.handleDBConnectionProperty.restore();
  297. });
  298. cases.forEach(function (item) {
  299. it(item.serviceName + ', ' + item.value, function () {
  300. view.get('serviceConfig').setProperties({
  301. serviceName: item.serviceName,
  302. value: item.value
  303. });
  304. expect(view.get('hostNameProperty.value')).to.equal(item.expected);
  305. expect(view.get('hostName')).to.equal(item.expected);
  306. });
  307. });
  308. });
  309. });
  310. describe('App.ServiceConfigRadioButton', function () {
  311. describe('#disabled', function () {
  312. var cases = [
  313. {
  314. wizardControllerName: 'addServiceController',
  315. value: 'New MySQL Database',
  316. title: 'Add Service Wizard, new database',
  317. disabled: false
  318. },
  319. {
  320. wizardControllerName: 'installerController',
  321. value: 'New MySQL Database',
  322. title: 'Install Wizard, new database',
  323. disabled: false
  324. },
  325. {
  326. wizardControllerName: 'addServiceController',
  327. value: 'Existing MySQL Database',
  328. title: 'Add Service Wizard, existing database',
  329. disabled: false
  330. },
  331. {
  332. wizardControllerName: 'installerController',
  333. value: 'Existing MySQL Database',
  334. title: 'Install Wizard, existing database',
  335. disabled: false
  336. },
  337. {
  338. wizardControllerName: null,
  339. value: 'New MySQL Database',
  340. title: 'No installer, new database',
  341. disabled: true
  342. },
  343. {
  344. wizardControllerName: null,
  345. value: 'Existing MySQL Database',
  346. title: 'No installer, existing database',
  347. disabled: false
  348. }
  349. ];
  350. cases.forEach(function (item) {
  351. it(item.title, function () {
  352. var view = App.ServiceConfigRadioButton.create({
  353. parentView: Em.Object.create({
  354. serviceConfig: Em.Object.create()
  355. }),
  356. controller: Em.Object.create({
  357. wizardController: Em.Object.create({
  358. name: null
  359. })
  360. })
  361. });
  362. view.set('value', item.value);
  363. view.set('controller.wizardController.name', item.wizardControllerName);
  364. view.set('parentView.serviceConfig.isEditable', true);
  365. expect(view.get('disabled')).to.equal(item.disabled);
  366. });
  367. });
  368. it('parent view is disabled', function () {
  369. var view = view = App.ServiceConfigRadioButton.create({
  370. parentView: Em.Object.create({
  371. serviceConfig: Em.Object.create()
  372. })
  373. });
  374. view.set('parentView.serviceConfig.isEditable', false);
  375. expect(view.get('disabled')).to.be.true;
  376. });
  377. });
  378. });