config_groups_mapper_test.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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('mappers/configs/config_groups_mapper');
  20. describe('App.configGroupsMapper', function () {
  21. var allHosts = App.get('allHostNames');
  22. var defaultAllHosts = ['host1', 'host2', 'host3'];
  23. beforeEach(function () {
  24. App.set('allHostNames', defaultAllHosts);
  25. });
  26. afterEach(function(){
  27. App.set('allHostNames', allHosts);
  28. });
  29. describe("#map", function() {
  30. var json = {
  31. "items" : [
  32. {
  33. "ConfigGroup" : {
  34. "cluster_name" : "1",
  35. "description" : "1",
  36. "desired_configs" : [
  37. {
  38. "tag" : "version1426088081862",
  39. "type" : "hadoop-env"
  40. }
  41. ],
  42. "group_name" : "1",
  43. "hosts" : [
  44. {
  45. "host_name" : "host1"
  46. }
  47. ],
  48. "id" : 2,
  49. "tag" : "Service1"
  50. }
  51. },
  52. {
  53. "ConfigGroup" : {
  54. "cluster_name" : "1",
  55. "description" : "hdfs2",
  56. "desired_configs" : [ ],
  57. "group_name" : "hdfs2",
  58. "hosts" : [
  59. {
  60. "host_name" : "host2"
  61. }
  62. ],
  63. "id" : 3,
  64. "tag" : "Service1"
  65. }
  66. },
  67. {
  68. "ConfigGroup" : {
  69. "cluster_name" : "1",
  70. "description" : "yarn1",
  71. "desired_configs" : [ ],
  72. "group_name" : "yarn1",
  73. "hosts" : [
  74. {
  75. "host_name" : "host1"
  76. },
  77. {
  78. "host_name" : "host2"
  79. }
  80. ],
  81. "id" : 4,
  82. "tag" : "Service2"
  83. }
  84. }
  85. ]
  86. };
  87. beforeEach(function () {
  88. App.resetDsStoreTypeMap(App.ServiceConfigGroup);
  89. App.resetDsStoreTypeMap(App.Service);
  90. sinon.stub(App.store, 'commit', Em.K);
  91. });
  92. afterEach(function(){
  93. App.store.commit.restore();
  94. });
  95. it('should not do anything as there is no serviceName', function() {
  96. App.configGroupsMapper.map(json);
  97. expect(App.ServiceConfigGroup.find().get('length')).to.equal(0);
  98. });
  99. it('should generate default groups for services', function() {
  100. App.Service.createRecord({'id': 'Service1'});
  101. App.configGroupsMapper.map(null, ["Service1"]);
  102. expect(App.ServiceConfigGroup.find().get('length')).to.equal(1);
  103. expect(App.ServiceConfigGroup.find('Service10').get('id')).to.eql('Service10');
  104. expect(App.ServiceConfigGroup.find('Service10').get('configGroupId')).to.eql(-1);
  105. expect(App.ServiceConfigGroup.find('Service10').get('name')).to.eql('Service1 Default');
  106. expect(App.ServiceConfigGroup.find('Service10').get('description')).to.eql('Default cluster level Service1 configuration');
  107. expect(App.ServiceConfigGroup.find('Service10').get('hostNames')).to.eql(defaultAllHosts);
  108. expect(App.ServiceConfigGroup.find('Service10').get('serviceName')).to.eql('Service1');
  109. expect(App.ServiceConfigGroup.find('Service10').get('service.id')).to.eql('Service1');
  110. });
  111. it('should generate groups form json and default config groups', function() {
  112. App.Service.createRecord({'id': 'Service1'});
  113. App.Service.createRecord({'id': 'Service2'});
  114. App.configGroupsMapper.map(json, ["Service1", "Service2"]);
  115. expect(App.ServiceConfigGroup.find().get('length')).to.equal(5);
  116. expect(App.ServiceConfigGroup.find().mapProperty('id')).to.eql(["Service12", "Service13", "Service24", "Service10", "Service20"]);
  117. });
  118. it('should generate groups form json and default config groups and check data', function() {
  119. App.Service.createRecord({'id': 'Service1'});
  120. App.Service.createRecord({'id': 'Service2'});
  121. App.configGroupsMapper.map(json, ["Service1", "Service2"]);
  122. expect(App.ServiceConfigGroup.find('Service12').get('id')).to.eql('Service12');
  123. expect(App.ServiceConfigGroup.find('Service12').get('configGroupId')).to.eql(2);
  124. expect(App.ServiceConfigGroup.find('Service12').get('name')).to.eql('1');
  125. expect(App.ServiceConfigGroup.find('Service12').get('description')).to.eql('1');
  126. expect(App.ServiceConfigGroup.find('Service12').get('hostNames')).to.eql(["host1"]);
  127. expect(App.ServiceConfigGroup.find('Service12').get('serviceName')).to.eql('Service1');
  128. expect(App.ServiceConfigGroup.find('Service12').get('service.id')).to.eql('Service1');
  129. });
  130. });
  131. describe("generateDefaultGroup", function() {
  132. var tests = [
  133. {
  134. service: 's1',
  135. hosts: ['h1'],
  136. res: {
  137. id: 's10',
  138. config_group_id: '-1',
  139. name: 's1 Default',
  140. service_name: 's1',
  141. description: 'Default cluster level s1 configuration',
  142. host_names: ['h1'],
  143. service_id: 's1'
  144. },
  145. m: 'with hosts'
  146. },
  147. {
  148. service: 's1',
  149. res: {
  150. id: 's10',
  151. config_group_id: '-1',
  152. name: 's1 Default',
  153. service_name: 's1',
  154. description: 'Default cluster level s1 configuration',
  155. host_names: defaultAllHosts,
  156. service_id: 's1'
  157. },
  158. m: 'without hosts'
  159. }
  160. ];
  161. tests.forEach(function(t) {
  162. it('generates default config group mock object ' + t.m, function() {
  163. expect(App.configGroupsMapper.generateDefaultGroup(t.service, t.hosts)).to.be.eql(t.res);
  164. });
  165. });
  166. });
  167. });