1   /* 
2    * Copyright (c) 2004-2005 SLF4J.ORG
3    * Copyright (c) 2004-2005 QOS.CH
4    * 
5    * All rights reserved.
6    * 
7    * Permission is hereby granted, free of charge, to any person obtaining
8    * a copy of this software and associated documentation files (the
9    * "Software"), to  deal in  the Software without  restriction, including
10   * without limitation  the rights to  use, copy, modify,  merge, publish,
11   * distribute, and/or sell copies of  the Software, and to permit persons
12   * to whom  the Software is furnished  to do so, provided  that the above
13   * copyright notice(s) and this permission notice appear in all copies of
14   * the  Software and  that both  the above  copyright notice(s)  and this
15   * permission notice appear in supporting documentation.
16   * 
17   * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
18   * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
19   * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
20   * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
21   * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
22   * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
23   * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
24   * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
25   * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26   * 
27   * Except as  contained in  this notice, the  name of a  copyright holder
28   * shall not be used in advertising or otherwise to promote the sale, use
29   * or other dealings in this Software without prior written authorization
30   * of the copyright holder.
31   *
32   */
33  
34  package org.slf4j;
35  
36  import junit.framework.TestCase;
37  
38  
39  /**
40   * Test whether invoking the SLF4J API causes problems or not.
41   * 
42   * @author Ceki Gulcu
43   *
44   */
45  public class InvocationTest extends TestCase {
46  
47    public InvocationTest (String arg0) {
48      super(arg0);
49    }
50  
51    protected void setUp() throws Exception {
52      super.setUp();
53    }
54  
55    protected void tearDown() throws Exception {
56      super.tearDown();
57    }
58    
59    public void test1() {
60      Logger logger = LoggerFactory.getLogger("test1");
61      logger.debug("Hello world.");
62    }
63    
64    public void test2() {
65      Integer i1 = new Integer(1);
66      Integer i2 = new Integer(2);
67      Integer i3 = new Integer(3);
68      Exception e = new Exception("This is a test exception.");
69      Logger logger = LoggerFactory.getLogger("test2");
70      
71      logger.debug("Hello world 1.");
72      logger.debug("Hello world {}", i1);
73      logger.debug("val={} val={}", i1, i2);
74      logger.debug("val={} val={} val={}", new Object[]{i1, i2, i3});
75      
76      logger.debug("Hello world 2", e);
77      logger.info("Hello world 2.");
78   
79      
80      logger.warn("Hello world 3.");
81      logger.warn("Hello world 3", e);
82   
83    
84      logger.error("Hello world 4.");
85      logger.error("Hello world {}", new Integer(3)); 
86      logger.error("Hello world 4.", e);
87    }
88    
89    public void testNull() {
90      Logger logger = LoggerFactory.getLogger("testNull");
91      logger.debug(null);
92      logger.info(null);
93      logger.warn(null);
94      logger.error(null);
95      
96      Exception e = new Exception("This is a test exception.");
97      logger.debug(null, e);
98      logger.info(null, e);
99      logger.warn(null, e);
100     logger.error(null, e);
101   }
102   
103   public void testMarker() {
104     Logger logger = LoggerFactory.getLogger("testMarker");
105     Marker blue = MarkerFactory.getMarker("BLUE");
106     logger.debug(blue, "hello");
107     logger.info(blue, "hello");
108     logger.warn(blue, "hello");
109     logger.error(blue, "hello");
110     
111     logger.debug(blue, "hello {}", "world");
112     logger.info(blue, "hello {}", "world");
113     logger.warn(blue, "hello {}", "world");
114     logger.error(blue, "hello {}", "world");
115 
116     logger.debug(blue, "hello {} and {} ", "world", "universe");
117     logger.info(blue, "hello {} and {} ", "world", "universe");
118     logger.warn(blue, "hello {} and {} ", "world", "universe");
119     logger.error(blue, "hello {} and {} ", "world", "universe");
120   }
121   
122   public void testMDC() {
123     MDC.put("k", "v");
124     assertNull(MDC.get("k"));
125     MDC.remove("k");
126     assertNull(MDC.get("k"));
127     MDC.clear();
128   }
129 }