serverValidator_test.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. });