loggerserver_test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2010 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.messaging.LoggerServerTest');
  15. goog.setTestOnly('goog.messaging.LoggerServerTest');
  16. goog.require('goog.debug.LogManager');
  17. goog.require('goog.debug.Logger');
  18. goog.require('goog.log');
  19. goog.require('goog.log.Level');
  20. goog.require('goog.messaging.LoggerServer');
  21. goog.require('goog.testing.MockControl');
  22. goog.require('goog.testing.PropertyReplacer');
  23. goog.require('goog.testing.jsunit');
  24. goog.require('goog.testing.messaging.MockMessageChannel');
  25. var mockControl;
  26. var channel;
  27. var stubs;
  28. function setUpPage() {
  29. stubs = new goog.testing.PropertyReplacer();
  30. }
  31. function setUp() {
  32. mockControl = new goog.testing.MockControl();
  33. channel = new goog.testing.messaging.MockMessageChannel(mockControl);
  34. stubs.set(
  35. goog.debug.LogManager, 'getLogger',
  36. mockControl.createFunctionMock('goog.log.getLogger'));
  37. }
  38. function tearDown() {
  39. channel.dispose();
  40. stubs.reset();
  41. }
  42. function testCommandWithoutChannelName() {
  43. var mockLogger = mockControl.createStrictMock(goog.debug.Logger);
  44. goog.log.getLogger('test.object.Name').$returns(mockLogger);
  45. goog.log.log(
  46. mockLogger, goog.log.Level.SEVERE, '[remote logger] foo bar', null);
  47. mockControl.$replayAll();
  48. var server = new goog.messaging.LoggerServer(channel, 'log');
  49. channel.receive('log', {
  50. name: 'test.object.Name',
  51. level: goog.log.Level.SEVERE.value,
  52. message: 'foo bar',
  53. exception: null
  54. });
  55. mockControl.$verifyAll();
  56. server.dispose();
  57. }
  58. function testCommandWithChannelName() {
  59. var mockLogger = mockControl.createStrictMock(goog.debug.Logger);
  60. goog.log.getLogger('test.object.Name').$returns(mockLogger);
  61. goog.log.log(
  62. mockLogger, goog.log.Level.SEVERE, '[some channel] foo bar', null);
  63. mockControl.$replayAll();
  64. var server = new goog.messaging.LoggerServer(channel, 'log', 'some channel');
  65. channel.receive('log', {
  66. name: 'test.object.Name',
  67. level: goog.log.Level.SEVERE.value,
  68. message: 'foo bar',
  69. exception: null
  70. });
  71. mockControl.$verifyAll();
  72. server.dispose();
  73. }
  74. function testCommandWithException() {
  75. var mockLogger = mockControl.createStrictMock(goog.debug.Logger);
  76. goog.log.getLogger('test.object.Name').$returns(mockLogger);
  77. goog.log.log(
  78. mockLogger, goog.log.Level.SEVERE, '[some channel] foo bar',
  79. {message: 'Bad things', stack: ['foo', 'bar']});
  80. mockControl.$replayAll();
  81. var server = new goog.messaging.LoggerServer(channel, 'log', 'some channel');
  82. channel.receive('log', {
  83. name: 'test.object.Name',
  84. level: goog.log.Level.SEVERE.value,
  85. message: 'foo bar',
  86. exception: {message: 'Bad things', stack: ['foo', 'bar']}
  87. });
  88. mockControl.$verifyAll();
  89. server.dispose();
  90. }