config_group_test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 modelSetup = require('test/init_model_test');
  20. require('models/config_group');
  21. require('models/host');
  22. var configGroup,
  23. hostRecord,
  24. hosts = [
  25. Em.Object.create({
  26. id: 'host0',
  27. hostName: 'host0',
  28. hostComponents: []
  29. }),
  30. Em.Object.create({
  31. id: 'host1',
  32. hostName: 'host1',
  33. hostComponents: []
  34. })
  35. ],
  36. host = Em.Object.create({
  37. id: 'host0',
  38. hostName: 'host0',
  39. hostComponents: []
  40. }),
  41. properties = [
  42. {
  43. name: 'n0',
  44. value: 'v0'
  45. },
  46. {
  47. name: 'n1',
  48. value: 'v1'
  49. }
  50. ],
  51. setParentConfigGroup = function (configGroup, hosts) {
  52. configGroup.set('parentConfigGroup', App.ConfigGroup.create());
  53. configGroup.set('parentConfigGroup.hosts', hosts.mapProperty('hostName'));
  54. };
  55. describe('App.ConfigGroup', function () {
  56. beforeEach(function () {
  57. configGroup = App.ConfigGroup.create();
  58. });
  59. describe('#displayName', function () {
  60. it('should equal name if maximum length is not exceeded', function () {
  61. configGroup.set('name', 'n');
  62. expect(configGroup.get('displayName')).to.equal(configGroup.get('name'));
  63. });
  64. it('should be shortened if maximum length is exceeded', function () {
  65. var maxLength = App.config.CONFIG_GROUP_NAME_MAX_LENGTH;
  66. for (var i = maxLength + 1, name = ''; i--; ) {
  67. name += 'n';
  68. }
  69. configGroup.set('name', name);
  70. expect(configGroup.get('displayName')).to.contain('...');
  71. expect(configGroup.get('displayName')).to.have.length(2 * Math.floor(maxLength / 2) + 3);
  72. });
  73. });
  74. describe('#displayNameHosts', function () {
  75. it('should indicate the number of hosts', function () {
  76. var displayName = configGroup.get('displayName');
  77. configGroup.set('hosts', []);
  78. expect(configGroup.get('displayNameHosts')).to.equal(displayName + ' (0)');
  79. configGroup.set('hosts', hosts);
  80. expect(configGroup.get('displayNameHosts')).to.equal(displayName + ' (2)');
  81. });
  82. });
  83. describe('#availableHosts', function () {
  84. beforeEach(function () {
  85. App.clusterStatus.set('clusterState', 'DEFAULT');
  86. sinon.stub(App.Host, 'find', function() {
  87. return [host];
  88. });
  89. setParentConfigGroup(configGroup, hosts);
  90. });
  91. afterEach(function () {
  92. App.Host.find.restore();
  93. });
  94. it('should return an empty array as default', function () {
  95. configGroup.set('isDefault', true);
  96. expect(configGroup.get('availableHosts')).to.eql([]);
  97. });
  98. it('should return an empty array if there are no unused hosts', function () {
  99. configGroup.set('parentConfigGroup', App.ConfigGroup.create());
  100. expect(configGroup.get('availableHosts')).to.eql([]);
  101. });
  102. it('should take hosts from parentConfigGroup', function () {
  103. setParentConfigGroup(configGroup, hosts);
  104. configGroup.set('clusterHosts', hosts);
  105. expect(configGroup.get('availableHosts')).to.have.length(2);
  106. });
  107. });
  108. describe('#isAddHostsDisabled', function () {
  109. beforeEach(function () {
  110. hostRecord = App.Host.createRecord(host);
  111. setParentConfigGroup(configGroup, hosts);
  112. configGroup.set('isDefault', false);
  113. configGroup.reopen({availableHosts: [{}]});
  114. });
  115. afterEach(function () {
  116. modelSetup.deleteRecord(hostRecord);
  117. });
  118. it('should be false', function () {
  119. expect(configGroup.get('isAddHostsDisabled')).to.be.false;
  120. });
  121. it('should be true', function () {
  122. App.clusterStatus.set('clusterState', 'DEFAULT');
  123. configGroup.set('isDefault', true);
  124. expect(configGroup.get('isAddHostsDisabled')).to.be.true;
  125. configGroup.set('availableHosts', hosts);
  126. expect(configGroup.get('isAddHostsDisabled')).to.be.true;
  127. });
  128. });
  129. describe('#propertiesList', function () {
  130. it('should be formed from properties', function () {
  131. configGroup.set('properties', properties);
  132. properties.forEach(function (item) {
  133. Em.keys(item).forEach(function (prop) {
  134. expect(configGroup.get('propertiesList')).to.contain(item[prop]);
  135. });
  136. });
  137. expect(configGroup.get('propertiesList')).to.have.length(24);
  138. });
  139. });
  140. });