step4_controller_test.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 configs = Em.A([
  23. App.ServiceConfigProperty.create({ name: 'prop1', value: 'someVal1', identityType: 'user', category: 'Ambari Principals', serviceName: 'Cluster'})
  24. ]);
  25. controller.set('stepConfigs', controller.createServiceConfig(configs));
  26. it('configuration errors are absent, submit should be not disabled', function() {
  27. expect(controller.get('stepConfigs')[0].get('errorCount')).to.be.eql(0);
  28. expect(controller.get('isSubmitDisabled')).to.be.false;
  29. });
  30. it('config has invalid value, submit should be disabled', function() {
  31. var serviceConfig = controller.get('stepConfigs')[0];
  32. serviceConfig.get('configs').findProperty('name', 'prop1').set('value', '');
  33. expect(serviceConfig.get('errorCount')).to.be.eql(1);
  34. expect(controller.get('isSubmitDisabled')).to.be.true;
  35. });
  36. });
  37. describe('#createServiceConfig', function() {
  38. var controller = App.KerberosWizardStep4Controller.create({});
  39. it('should create instance of App.ServiceConfig', function() {
  40. controller.createServiceConfig([], []).forEach(function(item){
  41. expect(item).be.instanceof(App.ServiceConfig);
  42. });
  43. });
  44. });
  45. describe('#prepareConfigProperties', function() {
  46. before(function() {
  47. var controller = App.KerberosWizardStep4Controller.create({
  48. wizardController: {
  49. getDBProperty: function() {
  50. return Em.A([
  51. Em.Object.create({ name: 'realm', value: 'realm_value' })
  52. ]);
  53. }
  54. }
  55. });
  56. sinon.stub(App.Service, 'find').returns(Em.A([
  57. { serviceName: 'HDFS' }
  58. ]));
  59. this.result = controller.prepareConfigProperties(properties);
  60. });
  61. after(function() {
  62. App.Service.find.restore();
  63. });
  64. var properties = Em.A([
  65. Em.Object.create({ name: 'realm', value: '', serviceName: 'Cluster' }),
  66. Em.Object.create({ name: 'spnego_keytab', value: 'spnego_keytab_value', serviceName: 'Cluster' }),
  67. Em.Object.create({ name: 'hdfs_keytab', value: '', serviceName: 'HDFS', identityType: 'user', observesValueFrom: 'spnego_keytab' }),
  68. Em.Object.create({ name: 'falcon_keytab', value: 'falcon_keytab_value', serviceName: 'FALCON' }),
  69. Em.Object.create({ name: 'mapreduce_keytab', value: 'mapreduce_keytab_value', serviceName: 'MAPREDUCE2' }),
  70. Em.Object.create({ name: 'hdfs_principal', value: 'hdfs_principal_value', identityType: 'user', serviceName: 'HDFS' })
  71. ]);
  72. var propertyValidationCases = [
  73. {
  74. property: 'spnego_keytab',
  75. e: [
  76. { key: 'category', value: 'Global' },
  77. { key: 'observesValueFrom', absent: true }
  78. ]
  79. },
  80. {
  81. property: 'realm',
  82. e: [
  83. { key: 'category', value: 'Global' },
  84. { key: 'value', value: 'realm_value' }
  85. ]
  86. },
  87. {
  88. property: 'hdfs_keytab',
  89. e: [
  90. {key: 'category', value: 'Ambari Principals'},
  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. describe('#setStepConfigs', function() {
  121. describe('Add Service Wizard', function() {
  122. before(function() {
  123. sinon.stub(App.StackService, 'find').returns([
  124. Em.Object.create({
  125. serviceName: 'KERBEROS',
  126. configCategories: []
  127. }),
  128. Em.Object.create({
  129. serviceName: 'HDFS',
  130. configCategories: []
  131. }),
  132. Em.Object.create({
  133. serviceName: 'MAPREDUCE2'
  134. })
  135. ]);
  136. sinon.stub(App.Service, 'find').returns([
  137. Em.Object.create({
  138. serviceName: 'HDFS'
  139. }),
  140. Em.Object.create({
  141. serviceName: 'KERBEROS'
  142. })
  143. ]);
  144. var controller = App.KerberosWizardStep4Controller.create({
  145. selectedServiceNames: ['FALCON', 'MAPREDUCE2'],
  146. installedServiceNames: ['HDFS', 'KERBEROS'],
  147. wizardController: Em.Object.create({
  148. name: 'addServiceController',
  149. getDBProperty: function() {
  150. return Em.A([
  151. Em.Object.create({ name: 'realm', value: 'realm_value' }),
  152. Em.Object.create({ name: 'admin_principal', value: 'some_val1', defaultValue: 'some_val1', filename: 'krb5-conf.xml' }),
  153. Em.Object.create({ name: 'admin_password', value: 'some_password', defaultValue: 'some_password', filename: 'krb5-conf.xml' })
  154. ]);
  155. }
  156. })
  157. });
  158. controller.setStepConfigs(properties);
  159. this.result = controller.get('stepConfigs')[0].get('configs').concat(controller.get('stepConfigs')[1].get('configs'));
  160. });
  161. after(function() {
  162. App.StackService.find.restore();
  163. App.Service.find.restore();
  164. });
  165. var properties = Em.A([
  166. Em.Object.create({ name: 'realm', value: '', serviceName: 'Cluster' }),
  167. Em.Object.create({ name: 'spnego_keytab', value: 'spnego_keytab_value', serviceName: 'Cluster', isEditable: true }),
  168. Em.Object.create({ name: 'hdfs_keytab', value: '', serviceName: 'HDFS', observesValueFrom: 'spnego_keytab', isEditable: true }),
  169. Em.Object.create({ name: 'falcon_keytab', value: 'falcon_keytab_value', serviceName: 'FALCON', isEditable: true }),
  170. Em.Object.create({ name: 'mapreduce_keytab', value: 'mapreduce_keytab_value', serviceName: 'MAPREDUCE2', isEditable: true })
  171. ]);
  172. var propertiesEditableTests = [
  173. { name: 'spnego_keytab', e: false },
  174. { name: 'falcon_keytab', e: true },
  175. { name: 'hdfs_keytab', e: false },
  176. { name: 'mapreduce_keytab', e: true },
  177. { name: 'admin_principal', e: true },
  178. { name: 'admin_password', e: true }
  179. ];
  180. propertiesEditableTests.forEach(function(test) {
  181. it('Add Service: property `{0}` should be {1} editable'.format(test.name, !!test.e ? '' : 'not '), function() {
  182. expect(this.result.findProperty('name', test.name).get('isEditable')).to.eql(test.e);
  183. });
  184. });
  185. ['admin_principal', 'admin_password'].forEach(function(item) {
  186. it('property `{0}` should have empty value'.format(item), function() {
  187. expect(this.result.findProperty('name', item).get('value')).to.be.empty;
  188. });
  189. });
  190. });
  191. });
  192. });