definitions_configs_controller_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. var controller;
  20. describe('App.MainAlertDefinitionConfigsController', function () {
  21. beforeEach(function () {
  22. controller = App.MainAlertDefinitionConfigsController.create({
  23. allServices: ['service1', 'service2', 'service3'],
  24. allComponents: ['component1', 'component2', 'component3'],
  25. aggregateAlertNames: ['alertDefinitionName', 'alertDefinitionName2', 'alertDefinitionName3']
  26. });
  27. });
  28. describe('#renderConfigs()', function () {
  29. beforeEach(function () {
  30. controller.set('content', Em.Object.create({}));
  31. sinon.stub(controller, 'renderPortConfigs', function () {
  32. return [];
  33. });
  34. sinon.stub(controller, 'renderMetricConfigs', function () {
  35. return [];
  36. });
  37. sinon.stub(controller, 'renderWebConfigs', function () {
  38. return [];
  39. });
  40. sinon.stub(controller, 'renderScriptConfigs', function () {
  41. return [];
  42. });
  43. sinon.stub(controller, 'renderAggregateConfigs', function () {
  44. return [];
  45. });
  46. });
  47. afterEach(function () {
  48. controller.renderPortConfigs.restore();
  49. controller.renderMetricConfigs.restore();
  50. controller.renderWebConfigs.restore();
  51. controller.renderScriptConfigs.restore();
  52. controller.renderAggregateConfigs.restore();
  53. });
  54. it('should call renderPortConfigs method', function () {
  55. controller.set('content.type', 'PORT');
  56. controller.renderConfigs();
  57. expect(controller.renderPortConfigs.calledOnce).to.be.true;
  58. });
  59. it('should call renderMetricConfigs method', function () {
  60. controller.set('content.type', 'METRIC');
  61. controller.renderConfigs();
  62. expect(controller.renderMetricConfigs.calledOnce).to.be.true;
  63. });
  64. it('should call renderWebConfigs method', function () {
  65. controller.set('content.type', 'WEB');
  66. controller.renderConfigs();
  67. expect(controller.renderWebConfigs.calledOnce).to.be.true;
  68. });
  69. it('should call renderScriptConfigs method', function () {
  70. controller.set('content.type', 'SCRIPT');
  71. controller.renderConfigs();
  72. expect(controller.renderScriptConfigs.calledOnce).to.be.true;
  73. });
  74. it('should call renderAggregateConfigs method', function () {
  75. controller.set('content.type', 'AGGREGATE');
  76. controller.renderConfigs();
  77. expect(controller.renderAggregateConfigs.calledOnce).to.be.true;
  78. });
  79. });
  80. describe('#renderPortConfigs()', function () {
  81. it('should render array of configs with correct values', function () {
  82. controller.set('content', Em.Object.create({
  83. name: 'alertDefinitionName',
  84. service: {displayName: 'alertDefinitionService'},
  85. componentName: 'component1',
  86. scope: 'HOST',
  87. description: 'alertDefinitionDescription',
  88. interval: 60,
  89. thresholds: '10-20',
  90. uri: 'alertDefinitionUri',
  91. defaultPort: '777'
  92. }));
  93. var result = controller.renderPortConfigs();
  94. expect(result.length).to.equal(9);
  95. expect(result.someProperty('value', 'alertDefinitionName')).to.be.true;
  96. expect(result.someProperty('value', 'alertDefinitionService')).to.be.true;
  97. expect(result.someProperty('value', 'Component1')).to.be.true;
  98. expect(result.someProperty('value', 'Host')).to.be.true;
  99. expect(result.someProperty('value', 'alertDefinitionDescription')).to.be.true;
  100. expect(result.someProperty('value', 60)).to.be.true;
  101. expect(result.someProperty('value', '10-20')).to.be.true;
  102. expect(result.someProperty('value', 'alertDefinitionUri')).to.be.true;
  103. expect(result.someProperty('value', '777')).to.be.true;
  104. });
  105. });
  106. describe('#renderMetricConfigs()', function () {
  107. it('should render array of configs with correct values', function () {
  108. controller.set('content', Em.Object.create({
  109. name: 'alertDefinitionName',
  110. service: {displayName: 'alertDefinitionService'},
  111. componentName: 'component1',
  112. scope: 'HOST',
  113. description: 'alertDefinitionDescription',
  114. interval: 60,
  115. thresholds: '10-20',
  116. uri: {
  117. "http": "{{mapred-site/mapreduce.jobhistory.webapp.address}}",
  118. "https": "{{mapred-site/mapreduce.jobhistory.webapp.https.address}}",
  119. "https_property": "{{mapred-site/mapreduce.jobhistory.http.policy}}",
  120. "https_property_value": "HTTPS_ONLY",
  121. "default_port": 0.0
  122. },
  123. jmx: {
  124. propertyList: ['property1', 'property2'],
  125. value: 'jmxValue'
  126. },
  127. ganglia: {
  128. propertyList: null,
  129. value: null
  130. }
  131. }));
  132. var result = controller.renderMetricConfigs();
  133. expect(result.length).to.equal(10);
  134. expect(result.someProperty('value', 'alertDefinitionName')).to.be.true;
  135. expect(result.someProperty('value', 'alertDefinitionService')).to.be.true;
  136. expect(result.someProperty('value', 'Component1')).to.be.true;
  137. expect(result.someProperty('value', 'Host')).to.be.true;
  138. expect(result.someProperty('value', 'alertDefinitionDescription')).to.be.true;
  139. expect(result.someProperty('value', 60)).to.be.true;
  140. expect(result.someProperty('value', '10-20')).to.be.true;
  141. expect(result.someProperty('value', '{\"http\":\"{{mapred-site/mapreduce.jobhistory.webapp.address}}\",\"https\":\"{{mapred-site/mapreduce.jobhistory.webapp.https.address}}\"}')).to.be.true;
  142. expect(result.someProperty('value', 'property1\nproperty2')).to.be.true;
  143. expect(result.someProperty('value', 'jmxValue')).to.be.true;
  144. });
  145. });
  146. describe('#renderWebConfigs()', function () {
  147. it('should render array of configs with correct values', function () {
  148. controller.set('content', Em.Object.create({
  149. name: 'alertDefinitionName',
  150. service: {displayName: 'alertDefinitionService'},
  151. componentName: 'component1',
  152. scope: 'HOST',
  153. description: 'alertDefinitionDescription',
  154. interval: 60,
  155. thresholds: '10-20',
  156. uri: {
  157. "http": "{{mapred-site/mapreduce.jobhistory.webapp.address}}",
  158. "https": "{{mapred-site/mapreduce.jobhistory.webapp.https.address}}",
  159. "https_property": "{{mapred-site/mapreduce.jobhistory.http.policy}}",
  160. "https_property_value": "HTTPS_ONLY",
  161. "default_port": 0.0
  162. }
  163. }));
  164. var result = controller.renderWebConfigs();
  165. expect(result.length).to.equal(8);
  166. expect(result.someProperty('value', 'alertDefinitionName')).to.be.true;
  167. expect(result.someProperty('value', 'alertDefinitionService')).to.be.true;
  168. expect(result.someProperty('value', 'Component1')).to.be.true;
  169. expect(result.someProperty('value', 'Host')).to.be.true;
  170. expect(result.someProperty('value', 'alertDefinitionDescription')).to.be.true;
  171. expect(result.someProperty('value', 60)).to.be.true;
  172. expect(result.someProperty('value', '10-20')).to.be.true;
  173. expect(result.someProperty('value', '{\"http\":\"{{mapred-site/mapreduce.jobhistory.webapp.address}}\",\"https\":\"{{mapred-site/mapreduce.jobhistory.webapp.https.address}}\"}')).to.be.true;
  174. });
  175. });
  176. describe('#renderScriptConfigs()', function () {
  177. it('should render array of configs with correct values', function () {
  178. controller.set('content', Em.Object.create({
  179. name: 'alertDefinitionName',
  180. service: {displayName: 'alertDefinitionService'},
  181. componentName: 'component1',
  182. scope: 'HOST',
  183. description: 'alertDefinitionDescription',
  184. interval: 60,
  185. thresholds: '10-20',
  186. location: 'path to script'
  187. }));
  188. var result = controller.renderScriptConfigs();
  189. expect(result.length).to.equal(8);
  190. expect(result.someProperty('value', 'alertDefinitionName')).to.be.true;
  191. expect(result.someProperty('value', 'alertDefinitionService')).to.be.true;
  192. expect(result.someProperty('value', 'Component1')).to.be.true;
  193. expect(result.someProperty('value', 'Host')).to.be.true;
  194. expect(result.someProperty('value', 'alertDefinitionDescription')).to.be.true;
  195. expect(result.someProperty('value', 60)).to.be.true;
  196. expect(result.someProperty('value', '10-20')).to.be.true;
  197. expect(result.someProperty('value', 'path to script')).to.be.true;
  198. });
  199. });
  200. describe('#renderAggregateConfigs()', function () {
  201. it('should render array of configs with correct values', function () {
  202. controller.set('content', Em.Object.create({
  203. name: 'alertDefinitionName',
  204. description: 'alertDefinitionDescription'
  205. }));
  206. var result = controller.renderAggregateConfigs();
  207. expect(result.length).to.equal(2);
  208. expect(result.someProperty('value', 'alertDefinitionName')).to.be.true;
  209. expect(result.someProperty('value', 'alertDefinitionDescription')).to.be.true;
  210. });
  211. });
  212. describe('#editConfigs()', function () {
  213. it('should set previousValue, isDisabled for each config and change canEdit flag', function () {
  214. controller.set('configs', [
  215. Em.Object.create({value: 'value1', previousValue: '', isDisabled: true}),
  216. Em.Object.create({value: 'value2', previousValue: '', isDisabled: true}),
  217. Em.Object.create({value: 'value3', previousValue: '', isDisabled: true})
  218. ]);
  219. controller.set('canEdit', false);
  220. controller.editConfigs();
  221. expect(controller.get('configs').mapProperty('previousValue')).to.eql(['value1', 'value2', 'value3']);
  222. expect(controller.get('configs').someProperty('isDisabled', true)).to.be.false;
  223. expect(controller.get('canEdit')).to.be.true;
  224. });
  225. });
  226. describe('#cancelEditConfigs()', function () {
  227. it('should set previousValue, isDisabled for each config and change canEdit flag', function () {
  228. controller.set('configs', [
  229. Em.Object.create({value: '', previousValue: 'value1', isDisabled: false}),
  230. Em.Object.create({value: '', previousValue: 'value2', isDisabled: false}),
  231. Em.Object.create({value: '', previousValue: 'value3', isDisabled: false})
  232. ]);
  233. controller.set('canEdit', true);
  234. controller.cancelEditConfigs();
  235. expect(controller.get('configs').mapProperty('value')).to.eql(['value1', 'value2', 'value3']);
  236. expect(controller.get('configs').someProperty('isDisabled', false)).to.be.false;
  237. expect(controller.get('canEdit')).to.be.false;
  238. });
  239. });
  240. describe('#saveConfigs()', function () {
  241. it('should set previousValue, isDisabled for each config and change canEdit flag', function () {
  242. controller.set('configs', [
  243. Em.Object.create({isDisabled: true}),
  244. Em.Object.create({isDisabled: true}),
  245. Em.Object.create({isDisabled: true})
  246. ]);
  247. controller.set('canEdit', true);
  248. controller.saveConfigs();
  249. expect(controller.get('configs').someProperty('isDisabled', false)).to.be.false;
  250. expect(controller.get('canEdit')).to.be.false;
  251. });
  252. });
  253. });