stack_config_properties_mapper_test.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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('mappers/configs/stack_config_properties_mapper');
  20. describe.skip('App.stackConfigPropertiesMapper', function () {
  21. describe("#map", function () {
  22. var json = {
  23. items: [
  24. {
  25. "StackServices": {
  26. "service_name": "HBASE",
  27. "stack_name": "HDP",
  28. "stack_version": "2.2",
  29. "config_types": {
  30. "site1": {
  31. "supports": {
  32. "adding_forbidden": "false",
  33. "do_not_extend": "false",
  34. "final": "true"
  35. }
  36. }
  37. }
  38. },
  39. "configurations": [
  40. {
  41. "StackConfigurations": {
  42. "final": "false",
  43. "property_description": "desc1",
  44. "property_name": "p1",
  45. "property_display_name": "P1",
  46. "property_type": [],
  47. "property_value": "v1",
  48. "service_name": "s1",
  49. "stack_name": "HDP",
  50. "stack_version": "2.2",
  51. "type": "site1.xml",
  52. "property_depends_on": [
  53. {
  54. "name": "p5",
  55. "type": "site5"
  56. }
  57. ],
  58. "property_value_attributes": {
  59. "type": "int",
  60. "minimum": "512",
  61. "maximum": "10240",
  62. "unit": "MB"
  63. }
  64. },
  65. "dependencies": [
  66. {
  67. "StackConfigurationDependency": {
  68. "dependency_name": "p4",
  69. "dependency_type": "site4"
  70. }
  71. }
  72. ]
  73. }
  74. ]
  75. },
  76. {
  77. "StackServices": {
  78. "service_name": "HDFS",
  79. "stack_name": "HDP",
  80. "stack_version": "2.2",
  81. "config_types": {
  82. "site2": {
  83. "supports": {
  84. "adding_forbidden": "false",
  85. "do_not_extend": "false",
  86. "final": "true"
  87. }
  88. },
  89. "site3": {
  90. "supports": {
  91. "adding_forbidden": "false",
  92. "do_not_extend": "false",
  93. "final": "true"
  94. }
  95. }
  96. }
  97. },
  98. "configurations": [
  99. {
  100. "StackConfigurations": {
  101. "final": "false",
  102. "property_description": "desc3",
  103. "property_name": "p2",
  104. "property_display_name": "P2",
  105. "property_type": [],
  106. "property_value": "v2",
  107. "service_name": "s2",
  108. "stack_name": "HDP",
  109. "stack_version": "2.2",
  110. "type": "site2.xml"
  111. }
  112. },
  113. {
  114. "StackConfigurations": {
  115. "final": "false",
  116. "property_description": "desc3",
  117. "property_name": "p3",
  118. "property_display_name": "P3",
  119. "property_type": [],
  120. "property_value": "v3",
  121. "service_name": "s2",
  122. "stack_name": "HDP",
  123. "stack_version": "2.2",
  124. "type": "site3.xml"
  125. }
  126. },
  127. {
  128. "StackConfigurations": {
  129. "final": "false",
  130. "property_description": "desc4",
  131. "property_name": "p4",
  132. "property_display_name": "P4",
  133. "property_type": ["PASSWORD"],
  134. "property_value": "v4",
  135. "service_name": "s2",
  136. "stack_name": "HDP",
  137. "stack_version": "2.2",
  138. "type": "site3.xml"
  139. }
  140. },
  141. {
  142. "StackConfigurations": {
  143. "final": "false",
  144. "property_description": "desc5",
  145. "property_name": "p5",
  146. "property_display_name": "P5",
  147. "property_type": ["USER"],
  148. "property_value": "v4",
  149. "service_name": "s2",
  150. "stack_name": "HDP",
  151. "stack_version": "2.2",
  152. "type": "site3.xml"
  153. }
  154. }
  155. ]
  156. }
  157. ]
  158. };
  159. beforeEach(function () {
  160. App.resetDsStoreTypeMap(App.StackConfigProperty);
  161. sinon.stub(App.store, 'commit', Em.K);
  162. sinon.stub(App.StackService, 'find', function () {
  163. return Em.A()
  164. });
  165. });
  166. afterEach(function () {
  167. App.store.commit.restore();
  168. App.StackService.find.restore();
  169. });
  170. it('should not do anything as there is no json', function () {
  171. App.stackConfigPropertiesMapper.map(null);
  172. expect(App.StackConfigProperty.find().get('length')).to.equal(0);
  173. });
  174. describe('should load data to model', function () {
  175. beforeEach(function () {
  176. App.stackConfigPropertiesMapper.map(json);
  177. });
  178. it('5 properties are mapped', function () {
  179. expect(App.StackConfigProperty.find().get('length')).to.equal(5);
  180. });
  181. it('ids are valid', function () {
  182. expect(App.StackConfigProperty.find().mapProperty('id')).to.eql(['p1__site1', 'p2__site2', 'p3__site3', 'p4__site3', 'p5__site3']);
  183. });
  184. it('name is valid', function () {
  185. expect(App.StackConfigProperty.find('p1__site1').get('name')).to.be.equal('p1');
  186. });
  187. it('displayName is valid', function () {
  188. expect(App.StackConfigProperty.find('p1__site1').get('displayName')).to.be.equal('P1');
  189. });
  190. it('description is valid', function () {
  191. expect(App.StackConfigProperty.find('p1__site1').get('description')).to.be.equal('desc1');
  192. });
  193. it('recommendedValue is valid', function () {
  194. expect(App.StackConfigProperty.find('p1__site1').get('recommendedValue')).to.be.equal('v1');
  195. });
  196. it('recommendedIsFinal is valid', function () {
  197. expect(App.StackConfigProperty.find('p1__site1').get('recommendedIsFinal')).to.be.false;
  198. });
  199. it('serviceName is valid', function () {
  200. expect(App.StackConfigProperty.find('p1__site1').get('serviceName')).to.be.equal('s1');
  201. });
  202. it('stackName is valid', function () {
  203. expect(App.StackConfigProperty.find('p1__site1').get('stackName')).to.be.equal('HDP');
  204. });
  205. it('stackVersion is valid', function () {
  206. expect(App.StackConfigProperty.find('p1__site1').get('stackVersion')).to.be.equal('2.2');
  207. });
  208. it('type is valid', function () {
  209. expect(App.StackConfigProperty.find('p1__site1').get('type').toArray()).to.eql([]);
  210. });
  211. it('fileName is valid', function () {
  212. expect(App.StackConfigProperty.find('p1__site1').get('fileName')).to.be.equal('site1.xml');
  213. });
  214. it('propertyDependedBy is valid', function () {
  215. expect(App.StackConfigProperty.find('p1__site1').get('propertyDependedBy')).to.eql([
  216. {
  217. "type": "site4",
  218. "name": "p4"
  219. }
  220. ]);
  221. });
  222. it('propertyDependsOn is valid', function () {
  223. expect(App.StackConfigProperty.find('p1__site1').get('propertyDependsOn')).to.eql([
  224. {
  225. "type": "site5",
  226. "name": "p5"
  227. }
  228. ]);
  229. });
  230. it('valueAttributes is valid', function () {
  231. expect(App.StackConfigProperty.find('p1__site1').get('valueAttributes')).to.eql({
  232. "type": "int",
  233. "minimum": "512",
  234. "maximum": "10240",
  235. "unit": "MB"
  236. });
  237. });
  238. it('supportsFinal is valid', function () {
  239. expect(App.StackConfigProperty.find('p1__site1').get('supportsFinal')).to.be.true;
  240. });
  241. });
  242. it('should set "displayType" by "property_type" attribute', function () {
  243. App.stackConfigPropertiesMapper.map(json);
  244. var prop = App.StackConfigProperty.find().findProperty('name', 'p4');
  245. var prop2 = App.StackConfigProperty.find().findProperty('name', 'p5');
  246. expect(prop).to.be.ok;
  247. expect(prop.get('displayType')).to.be.equal('password');
  248. expect(prop2.get('displayType')).to.be.equal('user');
  249. });
  250. });
  251. describe('#_isRequired', function() {
  252. [
  253. {
  254. allow_empty: true,
  255. property_value: 'some',
  256. is_required: false,
  257. message: 'false for value "some" and "allow_empty" true'
  258. },
  259. {
  260. allow_empty: false,
  261. property_value: '',
  262. is_required: true,
  263. message: 'true for value "" and "allow_empty" false'
  264. },
  265. {
  266. allow_empty: false,
  267. property_value: null,
  268. is_required: false,
  269. message: 'false for value null" and "allow_empty" false'
  270. }
  271. ].forEach(function(c) {
  272. it(c.message, function() {
  273. expect(App.stackConfigPropertiesMapper._isRequired(c.allow_empty, c.property_value)).to.equal(c.is_required);
  274. })
  275. });
  276. });
  277. });