You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/01/26 19:29:55 UTC

svn commit: r903353 - /cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java

Author: dkulp
Date: Tue Jan 26 18:29:55 2010
New Revision: 903353

URL: http://svn.apache.org/viewvc?rev=903353&view=rev
Log:
Update logutils to allow parallel testing

Modified:
    cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java

Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java?rev=903353&r1=903352&r2=903353&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java Tue Jan 26 18:29:55 2010
@@ -34,16 +34,15 @@
 
 
 public class LogUtilsTest extends Assert {
-    private static final Logger LOG = LogUtils.getL7dLogger(LogUtilsTest.class);
-
 
     @Test
     public void testGetL7dLog() throws Exception {
-        assertNotNull("expected non-null logger", LOG);
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testGetL7dLog");
+        assertNotNull("expected non-null logger", log);
         assertEquals("unexpected resource bundle name",
                      BundleUtils.getBundleName(LogUtilsTest.class),
-                     LOG.getResourceBundleName());
-        Logger otherLogger = LogUtils.getL7dLogger(LogUtilsTest.class, "Messages");
+                     log.getResourceBundleName());
+        Logger otherLogger = LogUtils.getL7dLogger(LogUtilsTest.class, "Messages", "testGetL7dLog");
         assertEquals("unexpected resource bundle name",
                      BundleUtils.getBundleName(LogUtilsTest.class, "Messages"),
                      otherLogger.getResourceBundleName());
@@ -51,97 +50,109 @@
 
     @Test
     public void testHandleL7dMessage() throws Exception {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testHandleL7dMessage");
         Handler handler = EasyMock.createNiceMock(Handler.class);
-        LOG.addHandler(handler);
+        log.addHandler(handler);
         // handler called *before* localization of message
         LogRecord record = new LogRecord(Level.WARNING, "FOOBAR_MSG");
-        record.setResourceBundle(LOG.getResourceBundle());
+        record.setResourceBundle(log.getResourceBundle());
         EasyMock.reportMatcher(new LogRecordMatcher(record));
         handler.publish(record);
         EasyMock.replay(handler);
-        LOG.log(Level.WARNING, "FOOBAR_MSG");
+        log.log(Level.WARNING, "FOOBAR_MSG");
         EasyMock.verify(handler);
-        LOG.removeHandler(handler);
+        log.removeHandler(handler);
     }
     
     @Test
     public void testLogNoParamsOrThrowable() {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsOrThrowable");
         Handler handler = EasyMock.createNiceMock(Handler.class);
-        LOG.addHandler(handler);
+        log.addHandler(handler);
         // handler called *after* localization of message
         LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
         EasyMock.reportMatcher(new LogRecordMatcher(record));
         handler.publish(record);
         EasyMock.replay(handler);
-        LogUtils.log(LOG, Level.SEVERE, "SUB1_MSG");
+        LogUtils.log(log, Level.SEVERE, "SUB1_MSG");
         EasyMock.verify(handler);
-        LOG.removeHandler(handler);
+        log.removeHandler(handler);
     }
     
     @Test
     public void testLogNoParamsWithThrowable() {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsWithThrowable");
         Handler handler = EasyMock.createNiceMock(Handler.class);
-        LOG.addHandler(handler);
-        // handler called *after* localization of message
         Exception ex = new Exception("x");
         LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
         record.setThrown(ex);
         EasyMock.reportMatcher(new LogRecordMatcher(record));
         handler.publish(record);
         EasyMock.replay(handler);
-        LogUtils.log(LOG, Level.SEVERE, "SUB1_MSG", ex);
-        EasyMock.verify(handler);
-        LOG.removeHandler(handler);
+        synchronized (log) {
+            log.addHandler(handler);
+            // handler called *after* localization of message
+            LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex);
+            EasyMock.verify(handler);
+            log.removeHandler(handler);
+        }
     }
 
     @Test
     public void testLogParamSubstitutionWithThrowable() throws Exception {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogParamSubstitutionWithThrowable");
         Handler handler = EasyMock.createNiceMock(Handler.class);
-        LOG.addHandler(handler);
-        // handler called *after* localization of message
         Exception ex = new Exception();
         LogRecord record = new LogRecord(Level.SEVERE, "subbed in 1 only");
         record.setThrown(ex);
         EasyMock.reportMatcher(new LogRecordMatcher(record));
         handler.publish(record);
         EasyMock.replay(handler);
-        LogUtils.log(LOG, Level.SEVERE, "SUB1_MSG", ex, 1);
-        EasyMock.verify(handler);
-        LOG.removeHandler(handler);
+        synchronized (log) {
+            log.addHandler(handler);
+            LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex, 1);
+            EasyMock.verify(handler);
+            log.removeHandler(handler);
+        }
     }
 
     @Test
     public void testLogParamsSubstitutionWithThrowable() throws Exception {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null,
+                                           "testLogParamsSubstitutionWithThrowable");
         Handler handler = EasyMock.createNiceMock(Handler.class);
-        LOG.addHandler(handler);
-        // handler called *after* localization of message
         Exception ex = new Exception();
         LogRecord record = new LogRecord(Level.SEVERE, "subbed in 4 & 3");
         record.setThrown(ex);
         EasyMock.reportMatcher(new LogRecordMatcher(record));
         handler.publish(record);
         EasyMock.replay(handler);
-        LogUtils.log(LOG, Level.SEVERE, "SUB2_MSG", ex, new Object[] {3, 4});
-        EasyMock.verify(handler);
-        LOG.removeHandler(handler);
+        synchronized (log) {
+            log.addHandler(handler);
+            LogUtils.log(log, Level.SEVERE, "SUB2_MSG", ex, new Object[] {3, 4});
+            EasyMock.verify(handler);
+            log.removeHandler(handler);
+        }
     }
     @Test
     public void testCXF1420() throws Exception {
-        LogUtils.log(LOG, Level.SEVERE, "SQLException for SQL [{call FOO.ping(?, ?)}]");
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testCXF1420");
+        LogUtils.log(log, Level.SEVERE, "SQLException for SQL [{call FOO.ping(?, ?)}]");
     }    
     @Test
     public void testClassMethodNames() throws Exception {
+        Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testClassMethodNames");
         TestLogHandler handler = new TestLogHandler();
-        LOG.addHandler(handler);
+        log.addHandler(handler);
 
         // logger called directly
-        LOG.warning("hello");
+        log.warning("hello");
         
         String cname = handler.cname;
         String mname = handler.mname;
         
         // logger called through LogUtils
-        LogUtils.log(LOG, Level.WARNING,  "FOOBAR_MSG");
+        LogUtils.log(log, Level.WARNING,  "FOOBAR_MSG");
         
         assertEquals(cname, handler.cname);
         assertEquals(mname, handler.mname);