001: /*
002: * Copyright (c) 2004-2007 QOS.CH
003: *
004: * All rights reserved.
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining
007: * a copy of this software and associated documentation files (the
008: * "Software"), to deal in the Software without restriction, including
009: * without limitation the rights to use, copy, modify, merge, publish,
010: * distribute, and/or sell copies of the Software, and to permit persons
011: * to whom the Software is furnished to do so, provided that the above
012: * copyright notice(s) and this permission notice appear in all copies of
013: * the Software and that both the above copyright notice(s) and this
014: * permission notice appear in supporting documentation.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
017: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
019: * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
020: * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
021: * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
022: * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
023: * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
024: * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
025: *
026: * Except as contained in this notice, the name of a copyright holder
027: * shall not be used in advertising or otherwise to promote the sale, use
028: * or other dealings in this Software without prior written authorization
029: * of the copyright holder.
030: *
031: */
032:
033: package org.slf4j;
034:
035: import junit.framework.TestCase;
036:
037: /**
038: * Test whether invoking the SLF4J API causes problems or not.
039: *
040: * @author Ceki Gulcu
041: *
042: */
043: public class InvocationTest extends TestCase {
044:
045: public InvocationTest(String arg0) {
046: super (arg0);
047: }
048:
049: protected void setUp() throws Exception {
050: super .setUp();
051: }
052:
053: protected void tearDown() throws Exception {
054: super .tearDown();
055: }
056:
057: public void test1() {
058: Logger logger = LoggerFactory.getLogger("test1");
059: logger.debug("Hello world.");
060: }
061:
062: public void test2() {
063: Integer i1 = new Integer(1);
064: Integer i2 = new Integer(2);
065: Integer i3 = new Integer(3);
066: Exception e = new Exception("This is a test exception.");
067: Logger logger = LoggerFactory.getLogger("test2");
068:
069: logger.debug("Hello world 1.");
070: logger.debug("Hello world {}", i1);
071: logger.debug("val={} val={}", i1, i2);
072: logger.debug("val={} val={} val={}",
073: new Object[] { i1, i2, i3 });
074:
075: logger.debug("Hello world 2", e);
076: logger.info("Hello world 2.");
077:
078: logger.warn("Hello world 3.");
079: logger.warn("Hello world 3", e);
080:
081: logger.error("Hello world 4.");
082: logger.error("Hello world {}", new Integer(3));
083: logger.error("Hello world 4.", e);
084: }
085:
086: public void testNull() {
087: Logger logger = LoggerFactory.getLogger("testNull");
088: logger.debug(null);
089: logger.info(null);
090: logger.warn(null);
091: logger.error(null);
092:
093: Exception e = new Exception("This is a test exception.");
094: logger.debug(null, e);
095: logger.info(null, e);
096: logger.warn(null, e);
097: logger.error(null, e);
098: }
099:
100: public void testMarker() {
101: Logger logger = LoggerFactory.getLogger("testMarker");
102: Marker blue = MarkerFactory.getMarker("BLUE");
103: logger.debug(blue, "hello");
104: logger.info(blue, "hello");
105: logger.warn(blue, "hello");
106: logger.error(blue, "hello");
107:
108: logger.debug(blue, "hello {}", "world");
109: logger.info(blue, "hello {}", "world");
110: logger.warn(blue, "hello {}", "world");
111: logger.error(blue, "hello {}", "world");
112:
113: logger.debug(blue, "hello {} and {} ", "world", "universe");
114: logger.info(blue, "hello {} and {} ", "world", "universe");
115: logger.warn(blue, "hello {} and {} ", "world", "universe");
116: logger.error(blue, "hello {} and {} ", "world", "universe");
117: }
118:
119: public void testMDC() {
120: MDC.put("k", "v");
121: assertNull(MDC.get("k"));
122: MDC.remove("k");
123: assertNull(MDC.get("k"));
124: MDC.clear();
125: }
126: }
|