step4_test.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/installer/step4_controller');
  21. describe('App.InstallerStep4Controller', function () {
  22. var DEFAULT_SERVICES = ['HDFS'];
  23. var OPTIONAL_SERVICES = ['MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SQOOP', 'ZOOKEEPER', 'HCATALOG'];
  24. var controller = App.InstallerStep4Controller.create();
  25. controller.rawContent.forEach(function(item){
  26. item.isSelected = true;
  27. controller.pushObject(Ember.Object.create(item));
  28. });
  29. describe('#selectMinimum()', function () {
  30. it('should set isSelected is false on all non-default services and isSelected is true on all default services', function() {
  31. controller.selectMinimum();
  32. DEFAULT_SERVICES.forEach(function (serviceName) {
  33. expect(controller.findProperty('serviceName', serviceName).get('isSelected')).to.equal(true);
  34. });
  35. OPTIONAL_SERVICES.forEach(function (serviceName) {
  36. expect(controller.findProperty('serviceName', serviceName).get('isSelected')).to.equal(false);
  37. });
  38. })
  39. })
  40. describe('#selectAll()', function () {
  41. it('should set isSelected is true on all non-default services and isSelected is true on all default services', function() {
  42. controller.selectAll();
  43. DEFAULT_SERVICES.forEach(function (serviceName) {
  44. expect(controller.findProperty('serviceName', serviceName).get('isSelected')).to.equal(true);
  45. });
  46. OPTIONAL_SERVICES.forEach(function (serviceName) {
  47. expect(controller.findProperty('serviceName', serviceName).get('isSelected')).to.equal(true);
  48. });
  49. })
  50. })
  51. describe('#isAll()', function () {
  52. beforeEach(function() {
  53. DEFAULT_SERVICES.forEach(function(serviceName) {
  54. controller.findProperty('serviceName', serviceName).set('isSelected', true);
  55. });
  56. OPTIONAL_SERVICES.forEach(function(serviceName) {
  57. controller.findProperty('serviceName', serviceName).set('isSelected', true);
  58. });
  59. });
  60. it('should return true if isSelected is true for all services', function() {
  61. expect(controller.get('isAll')).to.equal(true);
  62. })
  63. it('should return false if isSelected is false for one of the services', function() {
  64. controller.findProperty('serviceName', 'HBASE').set('isSelected', false);
  65. expect(controller.get('isAll')).to.equal(false);
  66. })
  67. })
  68. describe('#isMinimum()', function () {
  69. beforeEach(function() {
  70. DEFAULT_SERVICES.forEach(function(serviceName) {
  71. controller.findProperty('serviceName', serviceName).set('isSelected', true);
  72. });
  73. OPTIONAL_SERVICES.forEach(function(serviceName) {
  74. controller.findProperty('serviceName', serviceName).set('isSelected', false);
  75. });
  76. });
  77. it('should return true if isSelected is true for all default services and isSelected is false for all optional services', function() {
  78. expect(controller.get('isMinimum')).to.equal(true);
  79. })
  80. it('should return false if isSelected is true for all default serices and isSelected is true for one of optional services', function() {
  81. controller.findProperty('serviceName', 'HBASE').set('isSelected', true);
  82. expect(controller.get('isMinimum')).to.equal(false);
  83. })
  84. })
  85. describe('#needToAddMapReduce', function() {
  86. describe('mapreduce not selected', function() {
  87. beforeEach(function() {
  88. controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', false);
  89. })
  90. it('should return true if Hive is selected and MapReduce is not selected', function() {
  91. controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
  92. expect(controller.needToAddMapReduce()).to.equal(true);
  93. })
  94. it('should return true if Pig is selected and MapReduce is not selected', function() {
  95. controller.findProperty('serviceName', 'PIG').set('isSelected', true);
  96. expect(controller.needToAddMapReduce()).to.equal(true);
  97. })
  98. it('should return true if Oozie is selected and MapReduce is not selected', function() {
  99. controller.findProperty('serviceName', 'OOZIE').set('isSelected', true);
  100. expect(controller.needToAddMapReduce()).to.equal(true);
  101. })
  102. })
  103. describe('mapreduce not selected', function() {
  104. beforeEach(function() {
  105. controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  106. })
  107. it('should return false if Hive is selected and MapReduce is selected', function() {
  108. controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
  109. expect(controller.needToAddMapReduce()).to.equal(false);
  110. })
  111. it('should return false if Pig is selected and MapReduce is not selected', function() {
  112. controller.findProperty('serviceName', 'PIG').set('isSelected', true);
  113. expect(controller.needToAddMapReduce()).to.equal(false);
  114. })
  115. it('should return false if Oozie is selected and MapReduce is not selected', function() {
  116. controller.findProperty('serviceName', 'OOZIE').set('isSelected', true);
  117. expect(controller.needToAddMapReduce()).to.equal(false);
  118. })
  119. })
  120. })
  121. describe('#saveSelectedServiceNamesToDB', function() {
  122. beforeEach(function() {
  123. DEFAULT_SERVICES.forEach(function(serviceName) {
  124. controller.findProperty('serviceName', serviceName).set('isSelected', true);
  125. });
  126. OPTIONAL_SERVICES.forEach(function(serviceName) {
  127. controller.findProperty('serviceName', serviceName).set('isSelected', true);
  128. });
  129. });
  130. it('should store the selected service names in App.db.selectedServiceNames', function() {
  131. App.db.setLoginName('tester');
  132. App.db.setClusterName('test');
  133. controller.saveSelectedServiceNamesToDB();
  134. // console.log('controller length=' + controller.get('length'));
  135. var selectedServiceNames = App.db.getSelectedServiceNames();
  136. // console.log('service length=' + selectedServiceNames.get('length'));
  137. expect(selectedServiceNames.length === DEFAULT_SERVICES.length + OPTIONAL_SERVICES.length).to.equal(true);
  138. })
  139. })
  140. })