configs_service_test.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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/host/configs_service');
  20. describe('App.MainHostServiceConfigsController', function () {
  21. var controller = App.MainHostServiceConfigsController.create({
  22. host: Em.Object.create()
  23. });
  24. describe('#filterServiceConfigs()', function () {
  25. var testCases = [
  26. {
  27. title: 'configCategories is empty',
  28. content: {
  29. configCategories: [],
  30. hostComponents: []
  31. },
  32. result: []
  33. },
  34. {
  35. title: 'Category hostComponentNames is null',
  36. content: {
  37. configCategories: [
  38. Em.Object.create({hostComponentNames: null})
  39. ],
  40. hostComponents: []
  41. },
  42. result: [
  43. Em.Object.create({hostComponentNames: null})
  44. ]
  45. },
  46. {
  47. title: 'Components of host are empty',
  48. content: {
  49. configCategories: [
  50. Em.Object.create({hostComponentNames: ['comp1']})
  51. ],
  52. hostComponents: []
  53. },
  54. result: []
  55. },
  56. {
  57. title: 'Host components do not match component of categories',
  58. content: {
  59. configCategories: [
  60. Em.Object.create({hostComponentNames: ['comp1']})
  61. ],
  62. hostComponents: [
  63. {
  64. componentName: 'comp2'
  65. }
  66. ]
  67. },
  68. result: []
  69. },
  70. {
  71. title: 'Host components match component of categories',
  72. content: {
  73. configCategories: [
  74. Em.Object.create({hostComponentNames: ['comp1']})
  75. ],
  76. hostComponents: [
  77. {
  78. componentName: 'comp1'
  79. }
  80. ]
  81. },
  82. result: [
  83. Em.Object.create({hostComponentNames: ['comp1']})
  84. ]
  85. }
  86. ];
  87. testCases.forEach(function (test) {
  88. it(test.title, function () {
  89. controller.set('host.hostComponents', test.content.hostComponents);
  90. expect(controller.filterServiceConfigs(test.content.configCategories)).to.eql(test.result);
  91. });
  92. });
  93. });
  94. describe('#constructUrlParams()', function () {
  95. it('loadedGroupToOverrideSiteToTagMap is empty', function () {
  96. var loadedGroupToOverrideSiteToTagMap = {};
  97. var configGroups = [];
  98. expect(controller.constructUrlParams(loadedGroupToOverrideSiteToTagMap, configGroups)).to.eql([]);
  99. expect(controller.get('typeTagToGroupMap')).to.eql({});
  100. });
  101. it('Group does not have hosts', function () {
  102. var loadedGroupToOverrideSiteToTagMap = {'group1': {}};
  103. var configGroups = [
  104. Em.Object.create({
  105. name: 'group1',
  106. hosts: []
  107. })
  108. ];
  109. expect(controller.constructUrlParams(loadedGroupToOverrideSiteToTagMap, configGroups)).to.eql([]);
  110. expect(controller.get('typeTagToGroupMap')).to.eql({});
  111. });
  112. it('Group does not contain current host', function () {
  113. controller.set('host.hostName', 'host2');
  114. var loadedGroupToOverrideSiteToTagMap = {'group1': {}};
  115. var configGroups = [
  116. Em.Object.create({
  117. name: 'group1',
  118. hosts: ['host1']
  119. })
  120. ];
  121. expect(controller.constructUrlParams(loadedGroupToOverrideSiteToTagMap, configGroups)).to.eql([]);
  122. expect(controller.get('typeTagToGroupMap')).to.eql({});
  123. });
  124. it('No type to tags relations in group', function () {
  125. var loadedGroupToOverrideSiteToTagMap = {'group1': {}};
  126. var configGroups = [
  127. Em.Object.create({
  128. name: 'group1',
  129. hosts: ['host2']
  130. })
  131. ];
  132. expect(controller.constructUrlParams(loadedGroupToOverrideSiteToTagMap, configGroups)).to.eql([]);
  133. expect(controller.get('typeTagToGroupMap')).to.eql({});
  134. });
  135. it('Input params are correct', function () {
  136. var loadedGroupToOverrideSiteToTagMap = {
  137. 'group1': {
  138. 'type1': 'tag1'
  139. }
  140. };
  141. var configGroups = [
  142. Em.Object.create({
  143. name: 'group1',
  144. hosts: ['host2']
  145. })
  146. ];
  147. expect(controller.constructUrlParams(loadedGroupToOverrideSiteToTagMap, configGroups)).to.eql(['(type=type1&tag=tag1)']);
  148. expect(controller.get('typeTagToGroupMap')['type1///tag1'].get('name')).to.equal('group1');
  149. });
  150. });
  151. describe('#loadServiceConfigHostsOverrides()', function () {
  152. beforeEach(function () {
  153. sinon.stub(controller, "constructUrlParams", function(){
  154. return controller.get('testUrlParams');
  155. });
  156. sinon.spy(App.ajax, "send");
  157. });
  158. afterEach(function () {
  159. controller.constructUrlParams.restore();
  160. App.ajax.send.restore();
  161. });
  162. it('configKeyToConfigMap and urlParams are empty', function () {
  163. var serviceConfigs = [];
  164. controller.set('testUrlParams', []);
  165. controller.loadServiceConfigHostsOverrides(serviceConfigs);
  166. expect(controller.get('configKeyToConfigMap')).to.eql({});
  167. expect(App.ajax.send.called).to.be.false;
  168. });
  169. it('configKeyToConfigMap and urlParams are correct', function () {
  170. var serviceConfigs = [{
  171. name: 'config1'
  172. }];
  173. controller.set('testUrlParams', ['params']);
  174. controller.loadServiceConfigHostsOverrides(serviceConfigs);
  175. expect(controller.get('configKeyToConfigMap')).to.eql({'config1': {
  176. name: 'config1'
  177. }});
  178. expect(App.ajax.send.calledOnce).to.be.true;
  179. });
  180. });
  181. describe('#loadServiceConfigHostsOverridesSuccessCallback()', function () {
  182. beforeEach(function () {
  183. sinon.spy(App.config, "handleSpecialProperties");
  184. });
  185. afterEach(function () {
  186. App.config.handleSpecialProperties.restore();
  187. });
  188. it('data.items is empty', function () {
  189. var data = {
  190. items: [
  191. {
  192. type: 'type1',
  193. tag: 'tag1',
  194. properties: {'prop1': 'value1'}
  195. }
  196. ]
  197. };
  198. controller.set('typeTagToGroupMap', {'type1///tag1': {}});
  199. controller.set('configKeyToConfigMap', {'prop1': {}});
  200. controller.loadServiceConfigHostsOverridesSuccessCallback(data);
  201. expect(App.config.handleSpecialProperties.calledWith({
  202. value: 'value1',
  203. isOriginalSCP: false,
  204. group: {}
  205. })).to.be.true;
  206. });
  207. });
  208. });