config_test.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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/config');
  21. describe('App.config', function () {
  22. App.supports.capacitySchedulerUi = true;
  23. describe('#identifyCategory', function () {
  24. var data = {};
  25. it('should return null if config doesn\'t have category', function () {
  26. expect(App.config.identifyCategory(data)).to.equal(null);
  27. });
  28. it('should return "AdvancedCoreSite" if filename "core-site.xml" and serviceName "HDFS"', function () {
  29. data = {
  30. serviceName: 'HDFS',
  31. filename: 'core-site.xml'
  32. };
  33. expect(App.config.identifyCategory(data).name).to.equal('AdvancedCoreSite');
  34. });
  35. it('should return "CapacityScheduler" if filename "capacity-scheduler.xml" and serviceName "YARN"', function () {
  36. data = {
  37. serviceName: 'YARN',
  38. filename: 'capacity-scheduler.xml'
  39. };
  40. expect(App.config.identifyCategory(data).name).to.equal('CapacityScheduler');
  41. });
  42. });
  43. describe('#handleSpecialProperties', function () {
  44. var config = {};
  45. it('value should be transformed to "1024" from "1024m"', function () {
  46. config = {
  47. displayType: 'int',
  48. value: '1024m',
  49. defaultValue: '1024m'
  50. };
  51. App.config.handleSpecialProperties(config);
  52. expect(config.value).to.equal('1024');
  53. expect(config.defaultValue).to.equal('1024');
  54. });
  55. it('value should be transformed to true from "true"', function () {
  56. config = {
  57. displayType: 'checkbox',
  58. value: 'true',
  59. defaultValue: 'true'
  60. };
  61. App.config.handleSpecialProperties(config);
  62. expect(config.value).to.equal(true);
  63. expect(config.defaultValue).to.equal(true);
  64. });
  65. it('value should be transformed to false from "false"', function () {
  66. config = {
  67. displayType: 'checkbox',
  68. value: 'false',
  69. defaultValue: 'false'
  70. };
  71. App.config.handleSpecialProperties(config);
  72. expect(config.value).to.equal(false);
  73. expect(config.defaultValue).to.equal(false);
  74. });
  75. });
  76. describe('#calculateConfigProperties', function () {
  77. var config = {};
  78. var isAdvanced = false;
  79. var advancedConfigs = [];
  80. it('isUserProperty should be true if config is custom(site.xml) and not advanced', function () {
  81. config = {
  82. serviceName: 'HDFS',
  83. filename: 'core-site.xml'
  84. };
  85. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  86. expect(config.isUserProperty).to.equal(true);
  87. });
  88. it('isUserProperty should be false if config from "capacity-scheduler.xml" or "mapred-queue-acls.xml" ', function () {
  89. config = {
  90. name: 'test',
  91. serviceName: 'MAPREDUCE',
  92. filename: 'capacity-scheduler.xml',
  93. isUserProperty: false
  94. };
  95. isAdvanced = true;
  96. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  97. expect(config.isUserProperty).to.equal(false);
  98. });
  99. it('isRequired should be false if config is advanced"', function () {
  100. config = {
  101. name: 'test',
  102. serviceName: 'HDFS',
  103. filename: 'core-site.xml'
  104. };
  105. isAdvanced = true;
  106. advancedConfigs = [{name:'test', filename: 'core-site.xml'}];
  107. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  108. expect(config.category).to.equal('Advanced');
  109. expect(config.isRequired).to.equal(true);
  110. expect(config.filename).to.equal('core-site.xml');
  111. });
  112. });
  113. describe('#fileConfigsIntoTextarea', function () {
  114. var filename = 'capacity-scheduler.xml';
  115. var configs = [
  116. {
  117. name: 'config1',
  118. value: 'value1',
  119. defaultValue: 'value1',
  120. filename: 'capacity-scheduler.xml'
  121. },
  122. {
  123. name: 'config2',
  124. value: 'value2',
  125. defaultValue: 'value2',
  126. filename: 'capacity-scheduler.xml'
  127. }
  128. ];
  129. it('two configs into textarea', function () {
  130. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  131. expect(result.length).to.equal(1);
  132. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
  133. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  134. });
  135. it('three config into textarea', function () {
  136. configs.push({
  137. name: 'config3',
  138. value: 'value3',
  139. defaultValue: 'value3',
  140. filename: 'capacity-scheduler.xml'
  141. });
  142. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  143. expect(result.length).to.equal(1);
  144. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  145. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  146. });
  147. it('one of three configs has different filename', function () {
  148. configs[1].filename = 'another filename';
  149. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  150. //result contains two configs: one with different filename and one textarea config
  151. expect(result.length).to.equal(2);
  152. expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
  153. expect(result[1].defaultValue).to.equal('config1=value1\nconfig3=value3\n');
  154. });
  155. it('none configs into empty textarea', function () {
  156. filename = 'capacity-scheduler.xml';
  157. configs.clear();
  158. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  159. expect(result.length).to.equal(1);
  160. expect(result[0].value).to.equal('');
  161. expect(result[0].defaultValue).to.equal('');
  162. });
  163. });
  164. describe('#textareaIntoFileConfigs', function () {
  165. var filename = 'capacity-scheduler.xml';
  166. var testData = [
  167. {
  168. configs: [Em.Object.create({
  169. "name": "capacity-scheduler",
  170. "value": "config1=value1",
  171. "filename": "capacity-scheduler.xml"
  172. })]
  173. },
  174. {
  175. configs: [Em.Object.create({
  176. "name": "capacity-scheduler",
  177. "value": "config1=value1\nconfig2=value2\n",
  178. "filename": "capacity-scheduler.xml"
  179. })]
  180. },
  181. {
  182. configs: [Em.Object.create({
  183. "name": "capacity-scheduler",
  184. "value": "config1=value1,value2\n",
  185. "filename": "capacity-scheduler.xml"
  186. })]
  187. },
  188. {
  189. configs: [Em.Object.create({
  190. "name": "capacity-scheduler",
  191. "value": "config1=value1 config2=value2\n",
  192. "filename": "capacity-scheduler.xml"
  193. })]
  194. }
  195. ];
  196. it('config1=value1 to one config', function () {
  197. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
  198. expect(result.length).to.equal(1);
  199. expect(result[0].value).to.equal('value1');
  200. expect(result[0].name).to.equal('config1');
  201. });
  202. it('config1=value1\\nconfig2=value2\\n to two configs', function () {
  203. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
  204. expect(result.length).to.equal(2);
  205. expect(result[0].value).to.equal('value1');
  206. expect(result[0].name).to.equal('config1');
  207. expect(result[1].value).to.equal('value2');
  208. expect(result[1].name).to.equal('config2');
  209. });
  210. it('config1=value1,value2\n to one config', function () {
  211. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
  212. expect(result.length).to.equal(1);
  213. expect(result[0].value).to.equal('value1,value2');
  214. expect(result[0].name).to.equal('config1');
  215. });
  216. it('config1=value1 config2=value2 to two configs', function () {
  217. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
  218. expect(result.length).to.equal(1);
  219. });
  220. });
  221. describe('#escapeXMLCharacters', function () {
  222. var testConfigs = [
  223. {
  224. html: '&>"',
  225. json: '&>"'
  226. },
  227. {
  228. html: '&>"'',
  229. json: '&>"\''
  230. },
  231. {
  232. html: '&>',
  233. json: '&>'
  234. },
  235. {
  236. html: '&&&',
  237. json: '&&&'
  238. },
  239. {
  240. html: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &> /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`',
  241. json: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &> /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`'
  242. }
  243. ];
  244. testConfigs.forEach(function(t){
  245. it('parsing html ' + t.html, function () {
  246. expect(t.json).to.equal(App.config.escapeXMLCharacters(t.html));
  247. });
  248. });
  249. });
  250. });