config_group_test.js 3.8 KB

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