1 package com.atlassian.plugin.osgi.container.felix;
2
3 import junit.framework.TestCase;
4 import org.apache.felix.framework.Logger;
5 import org.osgi.framework.BundleException;
6
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
9 import static org.mockito.Mockito.verify;
10 import static org.mockito.Mockito.verifyNoMoreInteractions;
11
12 public class TestFelixLoggerBridge extends TestCase
13 {
14 private org.slf4j.Logger log;
15
16 @Override
17 protected void setUp() throws Exception
18 {
19 super.setUp();
20 log = mock(org.slf4j.Logger.class);
21 }
22
23 public void testFrameworkLogInfo()
24 {
25 when(log.isInfoEnabled()).thenReturn(true);
26 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
27 bridge.doLog(null, Logger.LOG_INFO, "foo", null);
28 verify(log).info("foo");
29 }
30
31 public void testClassNotFound()
32 {
33 when(log.isInfoEnabled()).thenReturn(true);
34 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
35 bridge.doLog(null, Logger.LOG_WARNING, "foo", new ClassNotFoundException("foo"));
36 verify(log).debug("Class not found in bundle: foo");
37 }
38
39 public void testClassNotFoundOnDebug()
40 {
41 when(log.isInfoEnabled()).thenReturn(true);
42 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
43 bridge.doLog(null, Logger.LOG_WARNING, "*** foo", new ClassNotFoundException("*** foo", new ClassNotFoundException("bar")));
44 verify(log).debug("Class not found in bundle: *** foo");
45 }
46
47 public void testLameClassNotFound()
48 {
49 when(log.isInfoEnabled()).thenReturn(true);
50 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
51 verify(log).isDebugEnabled();
52 verify(log).isInfoEnabled();
53 bridge.doLog(null, Logger.LOG_WARNING, "org.springframework.foo", new ClassNotFoundException("org.springframework.foo"));
54 verifyNoMoreInteractions(log);
55 }
56
57 public void testLameClassNotFoundInDebug()
58 {
59 when(log.isInfoEnabled()).thenReturn(true);
60 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
61 verify(log).isDebugEnabled();
62 verify(log).isInfoEnabled();
63 bridge.doLog(null, Logger.LOG_WARNING, "*** org.springframework.foo",
64 new ClassNotFoundException("*** org.springframework.foo", new ClassNotFoundException("org.springframework.foo")));
65 verifyNoMoreInteractions(log);
66 }
67
68 public void testBundleExceptionsAreLogged()
69 {
70 when(log.isWarnEnabled()).thenReturn(true);
71 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
72 bridge.doLog(null, Logger.LOG_WARNING, "message", new BundleException("exception"));
73 verify(log).warn("message: exception");
74 }
75 }