step4_controller_test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. describe('App.KerberosWizardStep4Controller', function() {
  20. describe('#isSubmitDisabled', function() {
  21. var controller = App.KerberosWizardStep4Controller.create({});
  22. var configCategories = Em.A([
  23. App.ServiceConfigCategory.create({ name: 'Advanced', displayName: 'Advanced'})
  24. ]);
  25. var configs = Em.A([
  26. App.ServiceConfigProperty.create({ name: 'prop1', value: 'someVal1', category: 'Advanced'})
  27. ]);
  28. controller.set('stepConfigs', [controller.createServiceConfig(configCategories, configs)]);
  29. it('configuration errors are absent, submit should be not disabled', function() {
  30. expect(controller.get('stepConfigs')[0].get('errorCount')).to.be.eql(0);
  31. expect(controller.get('isSubmitDisabled')).to.be.false;
  32. });
  33. it('config has invalid value, submit should be disabled', function() {
  34. var serviceConfig = controller.get('stepConfigs')[0];
  35. serviceConfig.get('configs').findProperty('name', 'prop1').set('value', '');
  36. expect(serviceConfig.get('errorCount')).to.be.eql(1);
  37. expect(controller.get('isSubmitDisabled')).to.be.true;
  38. });
  39. });
  40. describe('#createServiceConfig', function() {
  41. var controller = App.KerberosWizardStep4Controller.create({});
  42. it('should create instance of App.ServiceConfig', function() {
  43. expect(controller.createServiceConfig([], [])).be.instanceof(App.ServiceConfig);
  44. });
  45. });
  46. describe('#prepareConfigProperties', function() {
  47. before(function() {
  48. var controller = App.KerberosWizardStep4Controller.create({
  49. wizardController: {
  50. getDBProperty: function() {
  51. return Em.A([
  52. Em.Object.create({ name: 'realm', value: 'realm_value' })
  53. ]);
  54. }
  55. }
  56. });
  57. sinon.stub(App.Service, 'find').returns(Em.A([
  58. { serviceName: 'HDFS' }
  59. ]));
  60. this.result = controller.prepareConfigProperties(properties);
  61. });
  62. after(function() {
  63. App.Service.find.restore();
  64. });
  65. var properties = Em.A([
  66. Em.Object.create({ name: 'realm', value: '', serviceName: 'Cluster' }),
  67. Em.Object.create({ name: 'spnego_keytab', value: 'spnego_keytab_value', serviceName: 'Cluster' }),
  68. Em.Object.create({ name: 'hdfs_keytab', value: '', serviceName: 'HDFS', observesValueFrom: 'spnego_keytab' }),
  69. Em.Object.create({ name: 'falcon_keytab', value: 'falcon_keytab_value', serviceName: 'FALCON' }),
  70. Em.Object.create({ name: 'mapreduce_keytab', value: 'mapreduce_keytab_value', serviceName: 'MAPREDUCE2' }),
  71. Em.Object.create({ name: 'hdfs_principal', value: 'hdfs_principal_value', serviceName: 'HDFS' })
  72. ]);
  73. var propertyValidationCases = [
  74. {
  75. property: 'spnego_keytab',
  76. e: [
  77. { key: 'category', value: 'General' },
  78. { key: 'observesValueFrom', absent: true },
  79. ]
  80. },
  81. {
  82. property: 'realm',
  83. e: [
  84. { key: 'category', value: 'General' },
  85. { key: 'value', value: 'realm_value' },
  86. ]
  87. },
  88. {
  89. property: 'hdfs_keytab',
  90. e: [
  91. { key: 'value', value: 'spnego_keytab_value' },
  92. { key: 'observesValueFrom', value: 'spnego_keytab' },
  93. ]
  94. }
  95. ];
  96. var absentPropertiesTest = ['falcon_keytab', 'mapreduce_keytab'];
  97. it('should contains properties only for installed services', function() {
  98. expect(this.result.mapProperty('serviceName').uniq()).to.be.eql(['Cluster', 'HDFS']);
  99. });
  100. absentPropertiesTest.forEach(function(item) {
  101. it('property `{0}` should be absent'.format(item), function() {
  102. expect(this.result.findProperty('name', item)).to.be.undefined;
  103. });
  104. }, this);
  105. propertyValidationCases.forEach(function(test) {
  106. it('property {0} should be created'.format(test.property), function() {
  107. expect(this.result.findProperty('name', test.property)).to.be.ok;
  108. });
  109. test.e.forEach(function(expected) {
  110. it('property `{0}` should have `{1}` with value `{2}`'.format(test.property, expected.key, expected.value), function() {
  111. if (!!expected.absent) {
  112. expect(this.result.findProperty('name', test.property)).to.not.have.deep.property(expected.key);
  113. } else {
  114. expect(this.result.findProperty('name', test.property)).to.have.deep.property(expected.key, expected.value);
  115. }
  116. }, this);
  117. }, this);
  118. });
  119. });
  120. });