Merge "Fixed publishDataChangeEvent in 2phase commit"
[controller.git] / opendaylight / logging / bridge / src / test / java / org / opendaylight / controller / logging / bridge / internal / LogListenerImplTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.logging.bridge.internal;
9
10 import org.junit.Test;
11 import org.osgi.framework.Bundle;
12 import org.osgi.framework.ServiceReference;
13 import org.osgi.service.log.LogEntry;
14 import org.osgi.service.log.LogService;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import static org.mockito.Mockito.doReturn;
19 import static org.mockito.Mockito.mock;
20
21 public class LogListenerImplTest {
22     private static final Logger logger = LoggerFactory.getLogger(LogListenerImplTest.class);
23
24     @Test
25     public void test() {
26         LogListenerImpl tested = new LogListenerImpl(logger);
27         tested.logged(getEntry("m1", null));
28         tested.logged(getEntry("m2", new RuntimeException()));
29     }
30
31     private LogEntry getEntry(final String message, final Exception e) {
32         return new LogEntry() {
33             @Override
34             public Bundle getBundle() {
35                 Bundle mock = mock(Bundle.class);
36                 doReturn(null).when(mock).getSymbolicName();
37                 return mock;
38             }
39
40             @Override
41             public ServiceReference getServiceReference() {
42                 return null;
43             }
44
45             @Override
46             public int getLevel() {
47                 return LogService.LOG_INFO;
48             }
49
50             @Override
51             public String getMessage() {
52                 return message;
53             }
54
55             @Override
56             public Throwable getException() {
57                 return e;
58             }
59
60             @Override
61             public long getTime() {
62                 return 0;
63             }
64         };
65     }
66
67 }