| 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 |
|
| 15 |
goog.provide('goog.messaging.LoggerServerTest'); |
| 16 |
goog.setTestOnly('goog.messaging.LoggerServerTest'); |
| 17 |
|
| 18 |
goog.require('goog.debug.LogManager'); |
| 19 |
goog.require('goog.debug.Logger'); |
| 20 |
goog.require('goog.log'); |
| 21 |
goog.require('goog.log.Level'); |
| 22 |
goog.require('goog.messaging.LoggerServer'); |
| 23 |
goog.require('goog.testing.MockControl'); |
| 24 |
goog.require('goog.testing.PropertyReplacer'); |
| 25 |
goog.require('goog.testing.jsunit'); |
| 26 |
goog.require('goog.testing.messaging.MockMessageChannel'); |
| 27 |
|
| 28 |
var mockControl; |
| 29 |
var channel; |
| 30 |
var stubs; |
| 31 |
|
| 32 |
function setUpPage() { |
| 33 |
stubs = new goog.testing.PropertyReplacer(); |
| 34 |
} |
| 35 |
|
| 36 |
function setUp() { |
| 37 |
mockControl = new goog.testing.MockControl(); |
| 38 |
channel = new goog.testing.messaging.MockMessageChannel(mockControl); |
| 39 |
stubs.set( |
| 40 |
goog.debug.LogManager, 'getLogger', |
| 41 |
mockControl.createFunctionMock('goog.log.getLogger')); |
| 42 |
} |
| 43 |
|
| 44 |
function tearDown() { |
| 45 |
channel.dispose(); |
| 46 |
stubs.reset(); |
| 47 |
} |
| 48 |
|
| 49 |
function testCommandWithoutChannelName() { |
| 50 |
var mockLogger = mockControl.createStrictMock(goog.debug.Logger); |
| 51 |
goog.log.getLogger('test.object.Name').$returns(mockLogger); |
| 52 |
goog.log.log( |
| 53 |
mockLogger, goog.log.Level.SEVERE, '[remote logger] foo bar', null); |
| 54 |
mockControl.$replayAll(); |
| 55 |
|
| 56 |
var server = new goog.messaging.LoggerServer(channel, 'log'); |
| 57 |
channel.receive('log', { |
| 58 |
name: 'test.object.Name', |
| 59 |
level: goog.log.Level.SEVERE.value, |
| 60 |
message: 'foo bar', |
| 61 |
exception: null |
| 62 |
}); |
| 63 |
mockControl.$verifyAll(); |
| 64 |
server.dispose(); |
| 65 |
} |
| 66 |
|
| 67 |
function testCommandWithChannelName() { |
| 68 |
var mockLogger = mockControl.createStrictMock(goog.debug.Logger); |
| 69 |
goog.log.getLogger('test.object.Name').$returns(mockLogger); |
| 70 |
goog.log.log( |
| 71 |
mockLogger, goog.log.Level.SEVERE, '[some channel] foo bar', null); |
| 72 |
mockControl.$replayAll(); |
| 73 |
|
| 74 |
var server = new goog.messaging.LoggerServer(channel, 'log', 'some channel'); |
| 75 |
channel.receive('log', { |
| 76 |
name: 'test.object.Name', |
| 77 |
level: goog.log.Level.SEVERE.value, |
| 78 |
message: 'foo bar', |
| 79 |
exception: null |
| 80 |
}); |
| 81 |
mockControl.$verifyAll(); |
| 82 |
server.dispose(); |
| 83 |
} |
| 84 |
|
| 85 |
function testCommandWithException() { |
| 86 |
var mockLogger = mockControl.createStrictMock(goog.debug.Logger); |
| 87 |
goog.log.getLogger('test.object.Name').$returns(mockLogger); |
| 88 |
goog.log.log( |
| 89 |
mockLogger, goog.log.Level.SEVERE, '[some channel] foo bar', |
| 90 |
{message: 'Bad things', stack: ['foo', 'bar']}); |
| 91 |
mockControl.$replayAll(); |
| 92 |
|
| 93 |
var server = new goog.messaging.LoggerServer(channel, 'log', 'some channel'); |
| 94 |
channel.receive('log', { |
| 95 |
name: 'test.object.Name', |
| 96 |
level: goog.log.Level.SEVERE.value, |
| 97 |
message: 'foo bar', |
| 98 |
exception: {message: 'Bad things', stack: ['foo', 'bar']} |
| 99 |
}); |
| 100 |
mockControl.$verifyAll(); |
| 101 |
server.dispose(); |
| 102 |
} |