1 package com.atlassian.plugin.osgi.container.felix;
2
3 import junit.framework.TestCase;
4 import org.apache.commons.logging.Log;
5 import org.apache.felix.framework.Logger;
6 import org.apache.felix.moduleloader.ResourceNotFoundException;
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 Log log;
15
16 @Override
17 protected void setUp() throws Exception
18 {
19 super.setUp();
20 log = mock(Log.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 testResourceNotFound()
40 {
41 when(log.isInfoEnabled()).thenReturn(true);
42 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
43 bridge.doLog(null, Logger.LOG_WARNING, "foo", new ResourceNotFoundException("foo"));
44 verify(log).trace("Resource not found in bundle: foo");
45 }
46
47 public void testClassNotFoundOnDebug()
48 {
49 when(log.isInfoEnabled()).thenReturn(true);
50 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
51 bridge.doLog(null, Logger.LOG_WARNING, "*** foo", new ClassNotFoundException("*** foo", new ClassNotFoundException("bar")));
52 verify(log).debug("Class not found in bundle: *** foo");
53 }
54
55 public void testLameClassNotFound()
56 {
57 when(log.isInfoEnabled()).thenReturn(true);
58 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
59 verify(log).isDebugEnabled();
60 verify(log).isInfoEnabled();
61 bridge.doLog(null, Logger.LOG_WARNING, "org.springframework.foo", new ClassNotFoundException("org.springframework.foo"));
62 verifyNoMoreInteractions(log);
63 }
64
65 public void testLameClassNotFoundInDebug()
66 {
67 when(log.isInfoEnabled()).thenReturn(true);
68 FelixLoggerBridge bridge = new FelixLoggerBridge(log);
69 verify(log).isDebugEnabled();
70 verify(log).isInfoEnabled();
71 bridge.doLog(null, Logger.LOG_WARNING, "*** org.springframework.foo",
72 new ClassNotFoundException("*** org.springframework.foo", new ClassNotFoundException("org.springframework.foo")));
73 verifyNoMoreInteractions(log);
74 }
75 }