flume_test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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('/views/main/service/services/flume');
  20. describe('App.MainDashboardServiceFlumeView', function () {
  21. var view;
  22. beforeEach(function() {
  23. view = App.MainDashboardServiceFlumeView.create({
  24. service: Em.Object.create({
  25. agents: []
  26. })
  27. });
  28. });
  29. describe("#content", function() {
  30. it("should return content", function() {
  31. view.set('service.agents', [
  32. {hostName: 'host1'},
  33. {hostName: 'host2'},
  34. {hostName: 'host2'}
  35. ]);
  36. view.propertyDidChange('content');
  37. expect(view.get('content').mapProperty('hostName')).to.be.eql(['host1', 'host2']);
  38. expect(view.get('content').mapProperty('rowspan')).to.be.eql([1, 2]);
  39. expect(view.get('content').mapProperty('firtstAgent')).to.be.eql([{hostName: 'host1'}, {hostName: 'host2'}]);
  40. });
  41. });
  42. describe("#summaryHeader", function() {
  43. beforeEach(function() {
  44. this.mock = sinon.stub(App.FlumeService, 'find');
  45. });
  46. afterEach(function() {
  47. this.mock.restore();
  48. });
  49. it("single host", function() {
  50. this.mock.returns([
  51. Em.Object.create({
  52. agents: [{}]
  53. })
  54. ]);
  55. view.set('service.flumeHandlersTotal', 1);
  56. view.propertyDidChange('summaryHeader');
  57. expect(view.get('summaryHeader')).to.be.equal(view.t("dashboard.services.flume.summary.title").format(1, "", 1, ""));
  58. });
  59. it("multiple hosts", function() {
  60. this.mock.returns([
  61. Em.Object.create({
  62. agents: [{}, {}]
  63. })
  64. ]);
  65. view.set('service.flumeHandlersTotal', 2);
  66. view.propertyDidChange('summaryHeader');
  67. expect(view.get('summaryHeader')).to.be.equal(view.t("dashboard.services.flume.summary.title").format(2, "s", 2, "s"));
  68. });
  69. });
  70. describe("#didInsertElement()", function() {
  71. var mock = {
  72. on: function(a1, a2, callback) {
  73. callback();
  74. }
  75. };
  76. beforeEach(function() {
  77. sinon.stub(view, 'filter');
  78. sinon.stub(view, 'setDropdownPosition');
  79. sinon.stub(mock, 'on');
  80. sinon.stub(view, '$').returns(mock);
  81. view.didInsertElement();
  82. });
  83. afterEach(function() {
  84. view.filter.restore();
  85. view.setDropdownPosition();
  86. mock.on.restore();
  87. view.$.restore();
  88. });
  89. it("filter should be called", function() {
  90. expect(view.filter.calledOnce).to.be.true;
  91. });
  92. it("setDropdownPosition should be called", function() {
  93. expect(view.filter.calledOnce).to.be.true;
  94. });
  95. });
  96. describe("#willDestroyElement()", function() {
  97. var mock = {
  98. off: Em.K
  99. };
  100. beforeEach(function() {
  101. sinon.stub(mock, 'off');
  102. sinon.stub(view, '$').returns(mock);
  103. view.willDestroyElement();
  104. });
  105. afterEach(function() {
  106. mock.off.restore();
  107. view.$.restore();
  108. });
  109. it("off should be called", function() {
  110. expect(mock.off.calledOnce).to.be.true;
  111. });
  112. });
  113. describe("#setActionsDropdownClasses()", function() {
  114. it("should disable dropdown", function() {
  115. view.reopen({
  116. content: [
  117. Em.Object.create({
  118. agents: [
  119. Em.Object.create({status: 'RUNNING'}),
  120. Em.Object.create({status: 'NOT_RUNNING'})
  121. ]
  122. })
  123. ]
  124. });
  125. view.setActionsDropdownClasses();
  126. var agents = view.get('content.0.agents');
  127. expect(agents[0].get('isStartAgentDisabled')).to.be.true;
  128. expect(agents[0].get('isStopAgentDisabled')).to.be.false;
  129. expect(agents[1].get('isStartAgentDisabled')).to.be.false;
  130. expect(agents[1].get('isStopAgentDisabled')).to.be.true;
  131. });
  132. });
  133. describe("#updateFlumeAgentsCount()", function() {
  134. it("should update flumeAgentsCount", function() {
  135. view.set('service', Em.Object.create({
  136. agents: [{}]
  137. }));
  138. view.updateFlumeAgentsCount();
  139. expect(view.get('flumeAgentsCount')).to.be.equal(1);
  140. });
  141. });
  142. describe("#showAgentInfo()", function() {
  143. beforeEach(function() {
  144. sinon.stub(view, 'setAgentMetrics');
  145. });
  146. afterEach(function() {
  147. view.setAgentMetrics.restore();
  148. });
  149. it("setAgentMetrics should be called", function() {
  150. var host = {hostName: 'host1'};
  151. view.showAgentInfo(host);
  152. expect(view.setAgentMetrics.calledWith(host)).to.be.true;
  153. expect(view.get('selectedHost')).to.be.eql(host);
  154. });
  155. });
  156. });