stack_config_properties_mapper_test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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('App.stackConfigPropertiesMapper', function () {
  21. describe("#map", function() {
  22. var json = { items: [
  23. {
  24. "StackServices" : {
  25. "service_name" : "HBASE",
  26. "stack_name" : "HDP",
  27. "stack_version" : "2.2",
  28. "config_types" : {
  29. "site1" : {
  30. "supports" : {
  31. "adding_forbidden" : "false",
  32. "do_not_extend" : "false",
  33. "final" : "true"
  34. }
  35. }
  36. }
  37. },
  38. "configurations" : [
  39. {
  40. "StackConfigurations" : {
  41. "final" : "false",
  42. "property_description" : "desc1",
  43. "property_name" : "p1",
  44. "property_display_name" : "P1",
  45. "property_type" : [ ],
  46. "property_value" : "v1",
  47. "service_name" : "s1",
  48. "stack_name" : "HDP",
  49. "stack_version" : "2.2",
  50. "type" : "site1.xml",
  51. "property_depends_on": [
  52. {
  53. "name": "p5",
  54. "type": "site5"
  55. }
  56. ],
  57. "property_value_attributes": {
  58. "type": "int",
  59. "minimum": "512",
  60. "maximum": "10240",
  61. "unit": "MB"
  62. }
  63. },
  64. "dependencies": [
  65. {
  66. "StackConfigurationDependency" : {
  67. "dependency_name" : "p4",
  68. "dependency_type" : "site4"
  69. }
  70. }
  71. ]
  72. }
  73. ]
  74. },
  75. {
  76. "StackServices" : {
  77. "service_name" : "HDFS",
  78. "stack_name" : "HDP",
  79. "stack_version" : "2.2",
  80. "config_types" : {
  81. "site2" : {
  82. "supports" : {
  83. "adding_forbidden" : "false",
  84. "do_not_extend" : "false",
  85. "final" : "true"
  86. }
  87. },
  88. "site3" : {
  89. "supports" : {
  90. "adding_forbidden" : "false",
  91. "do_not_extend" : "false",
  92. "final" : "true"
  93. }
  94. }
  95. }
  96. },
  97. "configurations" : [
  98. {
  99. "StackConfigurations" : {
  100. "final" : "false",
  101. "property_description" : "desc3",
  102. "property_name" : "p2",
  103. "property_display_name" : "P2",
  104. "property_type" : [ ],
  105. "property_value" : "v2",
  106. "service_name" : "s2",
  107. "stack_name" : "HDP",
  108. "stack_version" : "2.2",
  109. "type" : "site2.xml"
  110. }
  111. },
  112. {
  113. "StackConfigurations" : {
  114. "final" : "false",
  115. "property_description" : "desc3",
  116. "property_name" : "p3",
  117. "property_display_name" : "P3",
  118. "property_type" : [ ],
  119. "property_value" : "v3",
  120. "service_name" : "s2",
  121. "stack_name" : "HDP",
  122. "stack_version" : "2.2",
  123. "type" : "site3.xml"
  124. }
  125. },
  126. {
  127. "StackConfigurations" : {
  128. "final" : "false",
  129. "property_description" : "desc4",
  130. "property_name" : "p4",
  131. "property_display_name" : "P4",
  132. "property_type" : [ "PASSWORD" ],
  133. "property_value" : "v4",
  134. "service_name" : "s2",
  135. "stack_name" : "HDP",
  136. "stack_version" : "2.2",
  137. "type" : "site3.xml"
  138. }
  139. },
  140. {
  141. "StackConfigurations" : {
  142. "final" : "false",
  143. "property_description" : "desc5",
  144. "property_name" : "p5",
  145. "property_display_name" : "P5",
  146. "property_type" : [ "USER" ],
  147. "property_value" : "v4",
  148. "service_name" : "s2",
  149. "stack_name" : "HDP",
  150. "stack_version" : "2.2",
  151. "type" : "site3.xml"
  152. }
  153. }
  154. ]
  155. }
  156. ]};
  157. beforeEach(function () {
  158. App.resetDsStoreTypeMap(App.StackConfigProperty);
  159. sinon.stub(App.store, 'commit', Em.K);
  160. });
  161. afterEach(function(){
  162. App.store.commit.restore();
  163. });
  164. it('should not do anything as there is no json', function() {
  165. App.stackConfigPropertiesMapper.map(null);
  166. expect(App.StackConfigProperty.find().get('length')).to.equal(0);
  167. });
  168. it('should load data to model', function() {
  169. App.stackConfigPropertiesMapper.map(json);
  170. expect(App.StackConfigProperty.find().get('length')).to.equal(5);
  171. expect(App.StackConfigProperty.find().mapProperty('id')).to.eql(['p1__site1','p2__site2','p3__site3', 'p4__site3', 'p5__site3']);
  172. expect(App.StackConfigProperty.find('p1__site1').get('name')).to.eql('p1');
  173. expect(App.StackConfigProperty.find('p1__site1').get('displayName')).to.eql('P1');
  174. expect(App.StackConfigProperty.find('p1__site1').get('description')).to.eql('desc1');
  175. expect(App.StackConfigProperty.find('p1__site1').get('recommendedValue')).to.eql('v1');
  176. expect(App.StackConfigProperty.find('p1__site1').get('recommendedIsFinal')).to.be.false;
  177. expect(App.StackConfigProperty.find('p1__site1').get('serviceName')).to.eql('s1');
  178. expect(App.StackConfigProperty.find('p1__site1').get('stackName')).to.eql('HDP');
  179. expect(App.StackConfigProperty.find('p1__site1').get('stackVersion')).to.eql('2.2');
  180. expect(App.StackConfigProperty.find('p1__site1').get('type').toArray()).to.eql([]);
  181. expect(App.StackConfigProperty.find('p1__site1').get('fileName')).to.eql('site1.xml');
  182. expect(App.StackConfigProperty.find('p1__site1').get('propertyDependedBy')).to.eql([
  183. {
  184. "type": "site4",
  185. "name": "p4"
  186. }
  187. ]);
  188. expect(App.StackConfigProperty.find('p1__site1').get('propertyDependsOn')).to.eql([
  189. {
  190. "type": "site5",
  191. "name": "p5"
  192. }
  193. ]);
  194. expect(App.StackConfigProperty.find('p1__site1').get('valueAttributes')).to.eql({
  195. "type": "int",
  196. "minimum": "512",
  197. "maximum": "10240",
  198. "unit": "MB"
  199. });
  200. expect(App.StackConfigProperty.find('p1__site1').get('supportsFinal')).to.be.true;
  201. });
  202. it('should set "displayType" by "property_type" attribute', function() {
  203. App.stackConfigPropertiesMapper.map(json);
  204. var prop = App.StackConfigProperty.find().findProperty('name', 'p4');
  205. var prop2 = App.StackConfigProperty.find().findProperty('name', 'p5');
  206. expect(prop).to.be.ok;
  207. expect(prop.get('displayType')).to.be.eql('password');
  208. expect(prop2.get('displayType')).to.be.eql('user');
  209. });
  210. });
  211. });