serverValidator_test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.ServerValidatorMixin', function() {
  20. var mixinObject = Em.Object.extend(App.ServerValidatorMixin, {});
  21. describe('#validationSuccess', function() {
  22. var instanceObject;
  23. var genRespItem = function(name, filename, level, message) {
  24. return {
  25. type: 'configuration',
  26. 'config-name': name,
  27. 'config-type': filename,
  28. level: level,
  29. message: message
  30. };
  31. };
  32. var genResponse = function(items) {
  33. return {
  34. items: (items.map(function(item) { return genRespItem.apply(undefined, item); }))
  35. };
  36. };
  37. var genConfigs = function(configs) {
  38. return Em.Object.create({
  39. configs: (configs.map(function(item) {
  40. return Em.Object.create({ name: item[0], filename: item[1] });
  41. }))
  42. });
  43. };
  44. var tests = [
  45. {
  46. stepConfigs: Em.A([
  47. genConfigs([
  48. ['prop1', 'some-site.xml']
  49. ])
  50. ]),
  51. resources: [
  52. genResponse([
  53. ['prop1', 'some-site', 'WARN', 'Some warn'],
  54. ['prop2', 'some-site', 'ERROR', 'Value should be set']
  55. ])
  56. ],
  57. expected: [
  58. { prop: 'configValidationError', value: true },
  59. { prop: 'configValidationWarning', value: true },
  60. { prop: 'configValidationGlobalMessage.length', value: 1 },
  61. { prop: 'configValidationGlobalMessage[0].serviceName', value: 'Some Service' },
  62. { prop: 'configValidationGlobalMessage[0].propertyName', value: 'prop2' }
  63. ],
  64. message: 'validation failed on absent property from step configs. global message should be showed.'
  65. },
  66. {
  67. stepConfigs: Em.A([
  68. genConfigs([
  69. ['prop1', 'some-site.xml'],
  70. ['prop2', 'some-site.xml']
  71. ])
  72. ]),
  73. resources: [
  74. genResponse([
  75. ['prop1', 'some-site', 'WARN', 'Some warn']
  76. ])
  77. ],
  78. expected: [
  79. { prop: 'configValidationError', value: false },
  80. { prop: 'configValidationWarning', value: true },
  81. { prop: 'configValidationGlobalMessage.length', value: 0}
  82. ],
  83. message: 'all properties present in step configs. validation failed. Present WARN and ERROR level messages.'
  84. },
  85. {
  86. stepConfigs: Em.A([
  87. genConfigs([
  88. ['prop1', 'some-site.xml'],
  89. ['prop2', 'some-site.xml']
  90. ])
  91. ]),
  92. resources: [
  93. {
  94. items: []
  95. }
  96. ],
  97. expected: [
  98. { prop: 'configValidationFailed', value: false },
  99. { prop: 'configValidationError', value: false },
  100. { prop: 'configValidationWarning', value: false },
  101. { prop: 'configValidationGlobalMessage.length', value: 0}
  102. ],
  103. message: 'validation success. no errors flags should be set.'
  104. }
  105. ];
  106. beforeEach(function() {
  107. instanceObject = mixinObject.create({});
  108. sinon.stub(App.StackService, 'find').returns([
  109. Em.Object.create({
  110. displayName: 'Some Service',
  111. configTypes: { 'some-site': {} }
  112. })
  113. ]);
  114. });
  115. afterEach(function() {
  116. App.StackService.find.restore();
  117. });
  118. tests.forEach(function(test) {
  119. it(test.message, function() {
  120. instanceObject.set('stepConfigs', test.stepConfigs);
  121. instanceObject.validationSuccess({resources: test.resources});
  122. test.expected.forEach(function(e) {
  123. expect(instanceObject).to.have.deep.property(e.prop, e.value);
  124. });
  125. });
  126. });
  127. });
  128. describe('#loadServerSideConfigsRecommendations', function() {
  129. describe('Request on recommendations for only specified controllers', function() {
  130. beforeEach(function() {
  131. sinon.stub(App.ajax, 'send', function(args) { return args; });
  132. });
  133. afterEach(function() {
  134. App.ajax.send.restore();
  135. });
  136. [
  137. {
  138. controllerName: '',
  139. injectEnhancedConfigsMixin: false,
  140. e: false
  141. },
  142. {
  143. controllerName: 'wizardStep7Controller',
  144. injectEnhancedConfigsMixin: true,
  145. e: true
  146. },
  147. {
  148. controllerName: 'kerberosWizardStep2Controller',
  149. injectEnhancedConfigsMixin: true,
  150. e: false
  151. }
  152. ].forEach(function(test) {
  153. it('controller "name": {0} using "EnhancedConfigsMixin": {1} recommendations called: {2}'.format(test.controllerName, test.injectEnhancedConfigsMixin, test.e), function() {
  154. var mixed;
  155. if (test.injectEnhancedConfigsMixin) {
  156. mixed = Em.Object.extend(App.EnhancedConfigsMixin, App.ServerValidatorMixin);
  157. } else {
  158. mixed = Em.Object.extend(App.ServerValidatorMixin);
  159. }
  160. // mock controller name in mixed object directly
  161. mixed.create({name: test.controllerName}).loadServerSideConfigsRecommendations();
  162. expect(App.ajax.send.calledOnce).to.be.eql(test.e);
  163. if (test.e) {
  164. expect(App.ajax.send.args[0][0].name).to.be.eql('config.recommendations');
  165. }
  166. });
  167. });
  168. });
  169. });
  170. });