serverValidator_test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. var instanceObject;
  22. beforeEach(function () {
  23. instanceObject = mixinObject.create();
  24. });
  25. describe('#collectAllIssues', function () {
  26. var result = [];
  27. var stepConfigs = [
  28. Em.Object.create({
  29. serviceName: 'service1',
  30. configs: [
  31. Em.Object.create({
  32. id: 'c1_f1',
  33. name: 'c1',
  34. filename: 'f1',
  35. isVisible: true,
  36. hiddenBySection: false
  37. }),
  38. Em.Object.create({
  39. id: 'c2_f2',
  40. name: 'c2',
  41. filename: 'f2',
  42. isVisible: true,
  43. hiddenBySection: false
  44. }),
  45. Em.Object.create({
  46. id: 'c3_f3',
  47. name: 'c3',
  48. filename: 'f3',
  49. isVisible: true,
  50. hiddenBySection: false,
  51. warnMessage: 'warn3'
  52. }),
  53. Em.Object.create({
  54. id: 'c4_f4',
  55. name: 'c4',
  56. filename: 'f4',
  57. isVisible: false,
  58. hiddenBySection: false
  59. })
  60. ]
  61. })
  62. ];
  63. var response = {
  64. configErrorsMap: {
  65. 'c1_f1': {
  66. type: 'WARN',
  67. messages: ['warn1']
  68. },
  69. 'c2_f2': {
  70. type: 'ERROR',
  71. messages: ['error2']
  72. },
  73. 'c4_f4': {
  74. type: 'ERROR',
  75. messages: ['error4']
  76. }
  77. },
  78. generalErrors: [{
  79. type: 'GENERAL',
  80. messages: ['general issue']
  81. }]
  82. };
  83. beforeEach(function () {
  84. instanceObject.set('stepConfigs', stepConfigs);
  85. result = instanceObject.collectAllIssues(response.configErrorsMap, response.generalErrors);
  86. });
  87. it('should add server warnings', function () {
  88. var error = result.find(function(r) { return r.propertyName === 'c1' && r.filename === 'f1'; });
  89. expect(error.type).to.equal('WARN');
  90. expect(error.messages).to.eql(['warn1']);
  91. });
  92. it('should add server errors', function () {
  93. var error = result.find(function(r) { return r.propertyName === 'c2' && r.filename === 'f2'; });
  94. expect(error.type).to.equal('ERROR');
  95. expect(error.messages).to.eql(['error2']);
  96. });
  97. it('should add ui warning', function () {
  98. var error = result.find(function(r) { return r.propertyName === 'c3' && r.filename === 'f3'; });
  99. expect(error.type).to.equal('WARN');
  100. expect(error.messages).to.eql(['warn3']);
  101. });
  102. it('should add general issues', function () {
  103. var error = result.findProperty('type', 'GENERAL');
  104. expect(error.messages).to.eql(['general issue']);
  105. });
  106. it('should ignore issues for hidden configs', function () {
  107. var error = result.find(function(r) { return r.propertyName === 'c4' && r.filename === 'f4'; });
  108. expect(error).to.be.undefined;
  109. });
  110. });
  111. describe('#createErrorMessage', function() {
  112. var property = {
  113. name: 'p1',
  114. filename: 'f1',
  115. value: 'v1',
  116. description: 'd1'
  117. };
  118. beforeEach(function() {
  119. sinon.stub(App.StackService, 'find', function() {
  120. return Em.Object.create({
  121. displayName: 'sName'
  122. });
  123. });
  124. });
  125. afterEach(function() {
  126. App.StackService.find.restore();
  127. });
  128. it('creates warn object', function() {
  129. expect(instanceObject.createErrorMessage('WARN', property, ['msg1'])).to.eql({
  130. type: 'WARN',
  131. isError: false,
  132. isWarn: true,
  133. isGeneral: false,
  134. messages: ['msg1'],
  135. propertyName: 'p1',
  136. filename: 'f1',
  137. value: 'v1',
  138. description: 'd1',
  139. serviceName: 'sName'
  140. });
  141. });
  142. it('creates error object', function() {
  143. expect(instanceObject.createErrorMessage('ERROR', property, ['msg2'])).to.eql({
  144. type: 'ERROR',
  145. isError: true,
  146. isWarn: false,
  147. isGeneral: false,
  148. messages: ['msg2'],
  149. propertyName: 'p1',
  150. filename: 'f1',
  151. value: 'v1',
  152. description: 'd1',
  153. serviceName: 'sName'
  154. });
  155. });
  156. it('creates general issue object', function() {
  157. expect(instanceObject.createErrorMessage('GENERAL', null, ['msg3'])).to.eql({
  158. type: 'GENERAL',
  159. isError: false,
  160. isWarn: false,
  161. isGeneral: true,
  162. messages: ['msg3']
  163. });
  164. });
  165. it('creates general issue object', function() {
  166. expect(instanceObject.createErrorMessage.bind(instanceObject, 'WRONG TYPE', null, ['msg3']))
  167. .to.throw(Error, 'Unknown config error type WRONG TYPE');
  168. });
  169. });
  170. });