add_controller_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/wizard');
  20. require('controllers/main/service/add_controller');
  21. var addServiceController = null;
  22. describe('App.AddServiceController', function() {
  23. beforeEach(function () {
  24. addServiceController = App.AddServiceController.create({});
  25. });
  26. describe('#installAdditionalClients', function() {
  27. var t = {
  28. additionalClients: {
  29. componentName: "TEZ_CLIENT",
  30. hostNames: ["hostName1", "hostName2"]
  31. },
  32. additionalClientsWithoutHosts: {
  33. componentName: "TEZ_CLIENT",
  34. hostNames: []
  35. },
  36. RequestInfo: {
  37. "context": Em.I18n.t('requestInfo.installHostComponent') + ' ' + App.format.role("TEZ_CLIENT"),
  38. "query": "HostRoles/component_name=TEZ_CLIENT&HostRoles/host_name.in(hostName1,hostName2)"
  39. },
  40. Body: {
  41. HostRoles: {
  42. state: 'INSTALLED'
  43. }
  44. }
  45. };
  46. beforeEach(function () {
  47. sinon.spy($, 'ajax');
  48. sinon.stub(App, 'get', function(k) {
  49. if ('clusterName' === k) return 'tdk';
  50. return Em.get(App, k);
  51. });
  52. });
  53. afterEach(function () {
  54. $.ajax.restore();
  55. App.get.restore();
  56. });
  57. it('send request to install client', function () {
  58. addServiceController.set("content.additionalClients", [t.additionalClients]);
  59. addServiceController.installAdditionalClients();
  60. expect($.ajax.calledOnce).to.equal(true);
  61. expect(JSON.parse($.ajax.args[0][0].data).Body).to.deep.eql(t.Body);
  62. expect(JSON.parse($.ajax.args[0][0].data).RequestInfo).to.eql(t.RequestInfo);
  63. });
  64. it('should not send request to install client', function () {
  65. addServiceController.set("content.additionalClients", [t.additionalClientsWithoutHosts]);
  66. expect($.ajax.called).to.be.false;
  67. });
  68. });
  69. describe('#generateDataForInstallServices', function() {
  70. var tests = [{
  71. selected: ["YARN","HBASE"],
  72. res: {
  73. "context": Em.I18n.t('requestInfo.installServices'),
  74. "ServiceInfo": {"state": "INSTALLED"},
  75. "urlParams": "ServiceInfo/service_name.in(YARN,HBASE)"
  76. }
  77. },
  78. {
  79. selected: ['OOZIE'],
  80. res: {
  81. "context": Em.I18n.t('requestInfo.installServices'),
  82. "ServiceInfo": {"state": "INSTALLED"},
  83. "urlParams": "ServiceInfo/service_name.in(OOZIE,HDFS,YARN,MAPREDUCE,MAPREDUCE2)"
  84. }
  85. }];
  86. tests.forEach(function(t){
  87. it('should generate data with ' + t.selected.join(","), function () {
  88. expect(addServiceController.generateDataForInstallServices(t.selected)).to.be.eql(t.res);
  89. });
  90. });
  91. });
  92. describe('#saveServices', function() {
  93. beforeEach(function() {
  94. sinon.stub(addServiceController, 'setDBProperty', Em.K);
  95. });
  96. afterEach(function() {
  97. addServiceController.setDBProperty.restore();
  98. });
  99. var tests = [
  100. {
  101. appService: [
  102. Em.Object.create({ serviceName: 'HDFS' }),
  103. Em.Object.create({ serviceName: 'KERBEROS' })
  104. ],
  105. stepCtrlContent: Em.Object.create({
  106. content: Em.A([
  107. Em.Object.create({ serviceName: 'HDFS', isInstalled: true, isSelected: true }),
  108. Em.Object.create({ serviceName: 'YARN', isInstalled: false, isSelected: true })
  109. ])
  110. }),
  111. e: {
  112. selected: ['YARN'],
  113. installed: ['HDFS', 'KERBEROS']
  114. }
  115. },
  116. {
  117. appService: [
  118. Em.Object.create({ serviceName: 'HDFS' }),
  119. Em.Object.create({ serviceName: 'STORM' })
  120. ],
  121. stepCtrlContent: Em.Object.create({
  122. content: Em.A([
  123. Em.Object.create({ serviceName: 'HDFS', isInstalled: true, isSelected: true }),
  124. Em.Object.create({ serviceName: 'YARN', isInstalled: false, isSelected: true }),
  125. Em.Object.create({ serviceName: 'MAPREDUCE2', isInstalled: false, isSelected: true })
  126. ])
  127. }),
  128. e: {
  129. selected: ['YARN', 'MAPREDUCE2'],
  130. installed: ['HDFS', 'STORM']
  131. }
  132. }
  133. ];
  134. var message = '{0} installed, {1} selected. Installed list should be {2} and selected - {3}';
  135. tests.forEach(function(test) {
  136. var installed = test.appService.mapProperty('serviceName');
  137. var selected = test.stepCtrlContent.get('content').filterProperty('isSelected', true)
  138. .filterProperty('isInstalled', false).mapProperty('serviceName');
  139. it(message.format(installed, selected, test.e.installed, test.e.selected), function() {
  140. sinon.stub(App.Service, 'find').returns(test.appService);
  141. addServiceController.saveServices(test.stepCtrlContent);
  142. App.Service.find.restore();
  143. var savedServices = addServiceController.setDBProperty.withArgs('services').args[0][1];
  144. expect(savedServices.selectedServices).to.have.members(test.e.selected);
  145. expect(savedServices.installedServices).to.have.members(test.e.installed);
  146. });
  147. });
  148. });
  149. });