config_test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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('utils/config');
  20. describe('App.config', function () {
  21. App.supports.capacitySchedulerUi = true;
  22. describe('#identifyCategory', function () {
  23. var data = {};
  24. it('should return null if config doesn\'t have category', function () {
  25. expect(App.config.identifyCategory(data)).to.equal(null);
  26. });
  27. it('should return "AdvancedCoreSite" if filename "core-site.xml" and serviceName "HDFS"', function () {
  28. data = {
  29. serviceName: 'HDFS',
  30. filename: 'core-site.xml'
  31. }
  32. expect(App.config.identifyCategory(data).name).to.equal('AdvancedCoreSite');
  33. });
  34. it('should return "CapacityScheduler" if filename "capacity-scheduler.xml" and serviceName "MAPREDUCE"', function () {
  35. data = {
  36. serviceName: 'MAPREDUCE',
  37. filename: 'capacity-scheduler.xml'
  38. }
  39. expect(App.config.identifyCategory(data).name).to.equal('CapacityScheduler');
  40. });
  41. });
  42. describe('#handleSpecialProperties', function () {
  43. var config = {};
  44. it('value should be transformed to "1024" from "1024m"', function () {
  45. config = {
  46. displayType: 'int',
  47. value: '1024m',
  48. defaultValue: '1024m'
  49. };
  50. App.config.handleSpecialProperties(config);
  51. expect(config.value).to.equal('1024');
  52. expect(config.defaultValue).to.equal('1024');
  53. });
  54. it('value should be transformed to true from "true"', function () {
  55. config = {
  56. displayType: 'checkbox',
  57. value: 'true',
  58. defaultValue: 'true'
  59. };
  60. App.config.handleSpecialProperties(config);
  61. expect(config.value).to.equal(true);
  62. expect(config.defaultValue).to.equal(true);
  63. });
  64. it('value should be transformed to false from "false"', function () {
  65. config = {
  66. displayType: 'checkbox',
  67. value: 'false',
  68. defaultValue: 'false'
  69. };
  70. App.config.handleSpecialProperties(config);
  71. expect(config.value).to.equal(false);
  72. expect(config.defaultValue).to.equal(false);
  73. });
  74. });
  75. describe('#calculateConfigProperties', function () {
  76. var config = {};
  77. var isAdvanced = false;
  78. var advancedConfigs = [];
  79. it('isUserProperty should be true if config is custom(site.xml) and not advanced', function () {
  80. config = {
  81. serviceName: 'HDFS',
  82. filename: 'core-site.xml'
  83. };
  84. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  85. expect(config.isUserProperty).to.equal(true);
  86. });
  87. it('isUserProperty should be false if config from "capacity-scheduler.xml" or "mapred-queue-acls.xml" ', function () {
  88. config = {
  89. name: 'test',
  90. serviceName: 'MAPREDUCE',
  91. filename: 'capacity-scheduler.xml',
  92. isUserProperty: false
  93. };
  94. isAdvanced = true;
  95. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  96. expect(config.isUserProperty).to.equal(false);
  97. });
  98. it('isRequired should be false if config is advanced"', function () {
  99. config = {
  100. name: 'test',
  101. serviceName: 'HDFS',
  102. filename: 'core-site.xml'
  103. };
  104. isAdvanced = true;
  105. advancedConfigs = [{name:'test', filename: 'test.xml'}];
  106. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  107. expect(config.category).to.equal('Advanced');
  108. expect(config.isRequired).to.equal(true);
  109. expect(config.filename).to.equal('test.xml');
  110. });
  111. });
  112. });