config_group_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. var model;
  20. function getModel() {
  21. return App.ServiceConfigGroup.createRecord({
  22. parentConfigGroup: Em.Object.create({
  23. hosts: []
  24. })
  25. });
  26. }
  27. describe('App.ServiceConfigGroup', function () {
  28. beforeEach(function () {
  29. model = getModel();
  30. });
  31. describe("#displayName", function() {
  32. before(function () {
  33. sinon.stub(App.config, 'truncateGroupName');
  34. });
  35. after(function () {
  36. App.config.truncateGroupName.restore();
  37. });
  38. it("App.config.truncateGroupName should be called", function() {
  39. model.set('name', 'group1');
  40. model.get('displayName');
  41. expect(App.config.truncateGroupName.called).to.be.true;
  42. });
  43. });
  44. describe("#availableHosts", function() {
  45. it("default group", function() {
  46. model.reopen({
  47. isDefault: true
  48. });
  49. expect(model.get('availableHosts')).to.be.empty;
  50. });
  51. it("no cluster hosts", function() {
  52. model.reopen({
  53. isDefault: false,
  54. clusterHosts: []
  55. });
  56. expect(model.get('availableHosts')).to.be.empty;
  57. });
  58. it("cluster hosts used", function() {
  59. model.reopen({
  60. isDefault: false,
  61. clusterHosts: [
  62. Em.Object.create({id: 'g1'})
  63. ]
  64. });
  65. expect(model.get('availableHosts')).to.be.empty;
  66. });
  67. describe("cluster hosts not used", function() {
  68. var host = Em.Object.create({
  69. id: 'g1',
  70. hostComponents: [{componentName: 'c1'}]
  71. });
  72. beforeEach(function () {
  73. model.reopen({
  74. isDefault: false,
  75. clusterHosts: [host]
  76. });
  77. model.set('parentConfigGroup.hosts', ['g1']);
  78. });
  79. it('availableHosts is not empty', function () {
  80. expect(model.get('availableHosts')).to.be.not.empty;
  81. });
  82. it('1st host is selected', function () {
  83. expect(model.get('availableHosts')[0].get('selected')).to.be.false;
  84. });
  85. it('1st host components are correct', function () {
  86. expect(model.get('availableHosts')[0].get('hostComponentNames')).to.eql(['c1']);
  87. });
  88. it('1st host `host` is correct', function () {
  89. expect(model.get('availableHosts')[0].get('host')).to.eql(host);
  90. });
  91. });
  92. });
  93. describe("#propertiesList", function() {
  94. it("properties is null", function() {
  95. model.set('properties', null);
  96. expect(model.get('propertiesList')).to.be.empty;
  97. });
  98. it("properties is correct", function() {
  99. model.set('properties', [
  100. {
  101. name: 'p1',
  102. value: 'v1'
  103. }
  104. ]);
  105. expect(model.get('propertiesList')).to.equal('p1 : v1<br/>');
  106. });
  107. });
  108. describe("#getParentConfigGroupId()", function () {
  109. before(function () {
  110. sinon.stub(App.ServiceConfigGroup, 'groupId');
  111. });
  112. after(function () {
  113. App.ServiceConfigGroup.groupId.restore();
  114. });
  115. it("App.ServiceConfigGroup.groupId should be called", function () {
  116. App.ServiceConfigGroup.getParentConfigGroupId('S1');
  117. expect(App.ServiceConfigGroup.groupId.calledWith('S1', 'Default')).to.be.true;
  118. });
  119. });
  120. describe("#groupId()", function () {
  121. it("should return group id", function () {
  122. expect(App.ServiceConfigGroup.groupId('S1', 'g1')).to.be.equal('S1_g1');
  123. });
  124. });
  125. });