step6_test.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/wizard/step6_controller');
  21. describe('App.WizardStep6Controller', function () {
  22. var controller = App.WizardStep6Controller.create();
  23. controller.set('content', {
  24. hosts: {},
  25. masterComponentHosts: {},
  26. services: [
  27. Em.Object.create({
  28. serviceName: 'MAPREDUCE',
  29. isSelected: true
  30. }),
  31. Em.Object.create({
  32. serviceName: 'YARN',
  33. isSelected: true
  34. }),
  35. Em.Object.create({
  36. serviceName: 'HBASE',
  37. isSelected: true
  38. }),
  39. Em.Object.create({
  40. serviceName: 'HDFS',
  41. isSelected: true
  42. })
  43. ]
  44. });
  45. var HOSTS = [ 'host0', 'host1', 'host2', 'host3' ];
  46. var h = {};
  47. var m = [];
  48. HOSTS.forEach(function (hostName) {
  49. var obj = Em.Object.create({
  50. name: hostName,
  51. hostName: hostName,
  52. bootStatus: 'REGISTERED'
  53. });
  54. h[hostName] = obj;
  55. m.push(obj);
  56. });
  57. controller.set('content.hosts', h);
  58. controller.set('content.masterComponentHosts', m);
  59. controller.set('isMasters', false);
  60. describe('#loadStep', function() {
  61. controller.loadStep();
  62. it('Hosts are loaded', function() {
  63. expect(controller.get('hosts').length).to.equal(HOSTS.length);
  64. });
  65. it('Headers are loaded', function() {
  66. expect(controller.get('headers').length).not.to.equal(0);
  67. });
  68. });
  69. describe('#isAddHostWizard', function() {
  70. it('true if content.controllerName is addHostController', function() {
  71. controller.set('content.controllerName', 'addHostController');
  72. expect(controller.get('isAddHostWizard')).to.equal(true);
  73. });
  74. it('false if content.controllerName is not addHostController', function() {
  75. controller.set('content.controllerName', 'mainController');
  76. expect(controller.get('isAddHostWizard')).to.equal(false);
  77. });
  78. });
  79. describe('#isInstallerWizard', function() {
  80. it('true if content.controllerName is addHostController', function() {
  81. controller.set('content.controllerName', 'installerController');
  82. expect(controller.get('isInstallerWizard')).to.equal(true);
  83. });
  84. it('false if content.controllerName is not addHostController', function() {
  85. controller.set('content.controllerName', 'mainController');
  86. expect(controller.get('isInstallerWizard')).to.equal(false);
  87. });
  88. });
  89. describe('#isAddServiceWizard', function() {
  90. it('true if content.controllerName is addServiceController', function() {
  91. controller.set('content.controllerName', 'addServiceController');
  92. expect(controller.get('isAddServiceWizard')).to.equal(true);
  93. });
  94. it('false if content.controllerName is not addServiceController', function() {
  95. controller.set('content.controllerName', 'mainController');
  96. expect(controller.get('isAddServiceWizard')).to.equal(false);
  97. });
  98. });
  99. describe('#hasMasterComponents', function() {
  100. HOSTS.forEach(function(host) {
  101. it('Host ' + host + ' is master', function() {
  102. expect(controller.hasMasterComponents(host)).to.equal(true);
  103. });
  104. });
  105. var notMasterHost = 'NotMasterHost';
  106. it('Host ' + notMasterHost + ' is not master', function() {
  107. expect(controller.hasMasterComponents(notMasterHost)).to.equal(false);
  108. });
  109. });
  110. describe('#setAllNodes', function() {
  111. var test_config = [
  112. {
  113. title: 'DataNode',
  114. state: false
  115. },
  116. {
  117. title: 'DataNode',
  118. state: true
  119. },
  120. {
  121. title: 'TaskTracker',
  122. state: false
  123. },
  124. {
  125. title: 'TaskTracker',
  126. state: true
  127. }
  128. ];
  129. test_config.forEach(function(test) {
  130. it((test.state?'Select':'Deselect') + ' all ' + test.title, function() {
  131. controller.setAllNodes(test.title, test.state);
  132. var hosts = controller.get('hosts');
  133. hosts.forEach(function(host) {
  134. var cb = host.get('checkboxes').filterProperty('isInstalled', false).findProperty('title', test.title);
  135. if (cb) {
  136. expect(cb.get('checked')).to.equal(test.state);
  137. }
  138. });
  139. });
  140. });
  141. });
  142. describe('#isServiceSelected', function() {
  143. controller.get('content.services').forEach(function(service) {
  144. it(service.serviceName + ' is selected', function() {
  145. expect(controller.isServiceSelected(service.serviceName)).to.equal(true);
  146. });
  147. });
  148. var unselectedService = 'FAKESERVICE';
  149. it(unselectedService + ' is not selected', function() {
  150. expect(controller.isServiceSelected(unselectedService)).to.equal(false);
  151. });
  152. });
  153. describe('#validateEachComponent', function() {
  154. it('Nothing checked', function() {
  155. controller.get('hosts').forEach(function(host) {
  156. host.get('checkboxes').setEach('checked', false);
  157. });
  158. expect(controller.validateEachComponent('')).to.equal(false);
  159. });
  160. it('One slave is not selected for no one host', function() {
  161. controller.get('hosts').forEach(function(host) {
  162. host.get('checkboxes').forEach(function(checkbox, index) {
  163. checkbox.set('checked', index === 0);
  164. });
  165. });
  166. expect(controller.validateEachComponent('')).to.equal(false);
  167. });
  168. it('All checked', function() {
  169. controller.get('hosts').forEach(function(host) {
  170. host.get('checkboxes').forEach(function(checkbox) {
  171. checkbox.set('checked', true);
  172. });
  173. });
  174. expect(controller.validateEachComponent('')).to.equal(true);
  175. });
  176. });
  177. describe('#validateEachHost', function() {
  178. it('Nothing checked', function() {
  179. controller.get('hosts').forEach(function(host) {
  180. host.get('checkboxes').setEach('checked', false);
  181. });
  182. expect(controller.validateEachHost('')).to.equal(false);
  183. });
  184. it('One host doesn\'t have assigned slaves', function() {
  185. controller.get('hosts').forEach(function(host, index) {
  186. host.get('checkboxes').setEach('checked', index === 0);
  187. });
  188. expect(controller.validateEachHost('')).to.equal(false);
  189. });
  190. it('All checked', function() {
  191. controller.get('hosts').forEach(function(host) {
  192. host.get('checkboxes').setEach('checked', true);
  193. });
  194. expect(controller.validateEachHost('')).to.equal(true);
  195. });
  196. });
  197. });