misc_controller_test.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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('controllers/main/admin/misc_controller');
  20. describe('App.MainAdminMiscController', function () {
  21. var controller = App.MainAdminMiscController.create();
  22. describe('#setContentProperty()', function () {
  23. var testCases = [
  24. {
  25. title: 'key is null',
  26. content: {
  27. key: null,
  28. configName: 'cc',
  29. miscConfigs: []
  30. },
  31. result: {
  32. output: false,
  33. configValue: 'test'
  34. }
  35. },
  36. {
  37. title: 'configName is null',
  38. content: {
  39. key: 'key',
  40. configName: null,
  41. miscConfigs: []
  42. },
  43. result: {
  44. output: false,
  45. configValue: 'test'
  46. }
  47. },
  48. {
  49. title: 'misc configs array doesn\'t contain such a config',
  50. content: {
  51. key: 'key',
  52. configName: 'config1',
  53. miscConfigs: []
  54. },
  55. result: {
  56. output: false,
  57. configValue: 'test'
  58. }
  59. },
  60. {
  61. title: 'content doesn\'t contain such a key',
  62. content: {
  63. key: 'key',
  64. configName: 'config1',
  65. miscConfigs: [
  66. Em.Object.create({
  67. name: 'test_key'
  68. })
  69. ]
  70. },
  71. result: {
  72. output: false,
  73. configValue: 'test'
  74. }
  75. },
  76. {
  77. title: 'content property match config',
  78. content: {
  79. key: 'testKey',
  80. configName: 'test_key',
  81. miscConfigs: [
  82. Em.Object.create({
  83. name: 'test_key',
  84. value: 'testValue'
  85. })
  86. ]
  87. },
  88. result: {
  89. output: true,
  90. configValue: 'testValue'
  91. }
  92. }
  93. ];
  94. controller.set('content', Em.Object.create({testKey: 'test'}));
  95. testCases.forEach(function (test) {
  96. it(test.title, function () {
  97. var content = controller.get('content');
  98. expect(controller.setContentProperty(test.content.key, test.content.configName, test.content.miscConfigs)).to.equal(test.result.output);
  99. expect(content.get('testKey')).to.equal(test.result.configValue);
  100. });
  101. });
  102. });
  103. describe('#sortByOrder()', function () {
  104. var testCases = [
  105. {
  106. title: 'sortOrder is null',
  107. content: {
  108. sortOrder: null,
  109. arrayToSort: [
  110. {
  111. name: 'one',
  112. displayName: 'one'
  113. }
  114. ]
  115. },
  116. result: ['one']
  117. },
  118. {
  119. title: 'sortOrder is empty',
  120. content: {
  121. sortOrder: [],
  122. arrayToSort: [
  123. {
  124. name: 'one',
  125. displayName: 'one'
  126. }
  127. ]
  128. },
  129. result: ['one']
  130. },
  131. {
  132. title: 'sortOrder items don\'t match items of array',
  133. content: {
  134. sortOrder: ['one'],
  135. arrayToSort: [
  136. {name: 'two'}
  137. ]
  138. },
  139. result: []
  140. },
  141. {
  142. title: 'sort items in reverse order',
  143. content: {
  144. sortOrder: ['two', 'one'],
  145. arrayToSort: [
  146. Em.Object.create({
  147. name: 'one',
  148. displayName: 'one'
  149. }),
  150. Em.Object.create({
  151. name: 'two',
  152. displayName: 'two'
  153. })
  154. ]
  155. },
  156. result: ['two', 'one']
  157. },
  158. {
  159. title: 'sort items in correct order',
  160. content: {
  161. sortOrder: ['one', 'two'],
  162. arrayToSort: [
  163. Em.Object.create({
  164. name: 'one',
  165. displayName: 'one'
  166. }),
  167. Em.Object.create({
  168. name: 'two',
  169. displayName: 'two'
  170. })
  171. ]
  172. },
  173. result: ['one', 'two']
  174. }
  175. ];
  176. testCases.forEach(function (test) {
  177. it(test.title, function () {
  178. expect(controller.sortByOrder(test.content.sortOrder, test.content.arrayToSort).mapProperty('displayName')).to.eql(test.result);
  179. });
  180. });
  181. });
  182. describe('#setProxyUserGroupLabel()', function () {
  183. it('proxyuser_group config is absent', function () {
  184. var misc_configs = [];
  185. controller.setProxyUserGroupLabel(misc_configs);
  186. expect(misc_configs.findProperty('name', 'proxyuser_group')).to.be.undefined;
  187. });
  188. it('if currentStackVersionNumber less than 2.1 then label should be omitting "FALCON" service', function () {
  189. var misc_configs = [Em.Object.create({
  190. name: 'proxyuser_group',
  191. displayName: 'test'
  192. })];
  193. App.set('currentStackVersion', "HDP-2.0");
  194. controller.setProxyUserGroupLabel(misc_configs);
  195. expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('Proxy group for Hive, WebHCat and Oozie');
  196. });
  197. it('if currentStackVersionNumber equal 2.1 then label should stay the same', function () {
  198. var misc_configs = [Em.Object.create({
  199. name: 'proxyuser_group',
  200. displayName: 'test'
  201. })];
  202. App.set('currentStackVersion', "HDP-2.1");
  203. controller.setProxyUserGroupLabel(misc_configs);
  204. expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('test');
  205. });
  206. it('if currentStackVersionNumber higher than 2.1 then label should stay the same', function () {
  207. var misc_configs = [Em.Object.create({
  208. name: 'proxyuser_group',
  209. displayName: 'test'
  210. })];
  211. App.set('currentStackVersion', "HDP-2.2");
  212. controller.setProxyUserGroupLabel(misc_configs);
  213. expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('test');
  214. });
  215. })
  216. });