add_controller_test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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('#isServiceConfigurable', function() {
  27. var tests = [
  28. {
  29. services: [
  30. {serviceName: 'HDFS'},
  31. {serviceName: 'MAPREDUCE'},
  32. {serviceName: 'NAGIOS'}
  33. ],
  34. service: 'HDFS',
  35. m: 'Service is configurable',
  36. e: true
  37. },
  38. {
  39. services: [
  40. {serviceName: 'HDFS'},
  41. {serviceName: 'MAPREDUCE'},
  42. {serviceName: 'NAGIOS'}
  43. ],
  44. service: 'PIG',
  45. m: 'Service is not configurable',
  46. e: false
  47. },
  48. {
  49. services: [],
  50. service: 'HDFS',
  51. m: 'No services',
  52. e: false
  53. }
  54. ];
  55. tests.forEach(function(test) {
  56. var controller = App.AddServiceController.create({serviceConfigs: test.services});
  57. it('', function() {
  58. expect(controller.isServiceConfigurable(test.service)).to.equal(test.e);
  59. });
  60. });
  61. });
  62. describe('#skipConfigStep', function() {
  63. var tests = [
  64. {
  65. content: {
  66. services:[
  67. {serviceName: 'HDFS', isInstalled: true, isSelected: true},
  68. {serviceName: 'PIG', isInstalled: false, isSelected: true},
  69. {serviceName: 'MAPREDUCE', isInstalled: true, isSelected: true}
  70. ]
  71. },
  72. serviceConfigs: [
  73. {serviceName: 'HDFS'},
  74. {serviceName: 'MAPREDUCE'},
  75. {serviceName: 'NAGIOS'}
  76. ],
  77. m: '2 installed services and 1 new that can\'t be configured',
  78. e: true
  79. },
  80. {
  81. content: {
  82. services:[
  83. {serviceName: 'HDFS', isInstalled: true, isSelected: true},
  84. {serviceName: 'NAGIOS', isInstalled: false, isSelected: true},
  85. {serviceName: 'MAPREDUCE', isInstalled: true, isSelected: true}
  86. ]
  87. },
  88. serviceConfigs: [
  89. {serviceName: 'HDFS'},
  90. {serviceName: 'MAPREDUCE'},
  91. {serviceName: 'NAGIOS'}
  92. ],
  93. m: '2 installed services and 1 new that can be configured',
  94. e: false
  95. },
  96. {
  97. content: {
  98. services:[
  99. {serviceName: 'HDFS', isInstalled: true, isSelected: true},
  100. {serviceName: 'PIG', isInstalled: false, isSelected: true},
  101. {serviceName: 'SQOOP', isInstalled: false, isSelected: true},
  102. {serviceName: 'MAPREDUCE', isInstalled: true, isSelected: true}
  103. ]
  104. },
  105. serviceConfigs: [
  106. {serviceName: 'HDFS'},
  107. {serviceName: 'MAPREDUCE'},
  108. {serviceName: 'NAGIOS'}
  109. ],
  110. m: '2 installed services and 2 new that can\'t be configured',
  111. e: true
  112. }
  113. ];
  114. tests.forEach(function(test) {
  115. var controller = App.AddServiceController.create({content:{services: test.content.services}, serviceConfigs: test.serviceConfigs});
  116. it(test.m, function() {
  117. expect(controller.skipConfigStep()).to.equal(test.e);
  118. })
  119. });
  120. });
  121. describe('#installAdditionalClients', function() {
  122. var t = {
  123. additionalClients: {
  124. componentName: "TEZ_CLIENT",
  125. hostName: "hostName"
  126. },
  127. RequestInfo: {
  128. "context": Em.I18n.t('requestInfo.installHostComponent') + " hostName"
  129. },
  130. Body: {
  131. HostRoles: {
  132. state: 'INSTALLED'
  133. }
  134. }
  135. };
  136. beforeEach(function () {
  137. sinon.spy($, 'ajax');
  138. });
  139. afterEach(function () {
  140. $.ajax.restore();
  141. });
  142. it('send request to install client', function () {
  143. addServiceController.set("content.additionalClients", [t.additionalClients]);
  144. addServiceController.installAdditionalClients();
  145. expect($.ajax.calledOnce).to.equal(true);
  146. expect(JSON.parse($.ajax.args[0][0].data).Body).to.deep.eql(t.Body);
  147. expect(JSON.parse($.ajax.args[0][0].data).RequestInfo).to.eql(t.RequestInfo);
  148. });
  149. });
  150. });