KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > slf4j > InvocationTest


1 /*
2  * Copyright (c) 2004-2007 QOS.CH
3  *
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, and/or sell copies of the Software, and to permit persons
11  * to whom the Software is furnished to do so, provided that the above
12  * copyright notice(s) and this permission notice appear in all copies of
13  * the Software and that both the above copyright notice(s) and this
14  * permission notice appear in supporting documentation.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
19  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
21  * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
22  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
23  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25  *
26  * Except as contained in this notice, the name of a copyright holder
27  * shall not be used in advertising or otherwise to promote the sale, use
28  * or other dealings in this Software without prior written authorization
29  * of the copyright holder.
30  *
31  */

32
33 package org.slf4j;
34
35 import junit.framework.TestCase;
36
37
38 /**
39  * Test whether invoking the SLF4J API causes problems or not.
40  *
41  * @author Ceki Gulcu
42  *
43  */

44 public class InvocationTest extends TestCase {
45
46   public InvocationTest (String JavaDoc arg0) {
47     super(arg0);
48   }
49
50   protected void setUp() throws Exception JavaDoc {
51     super.setUp();
52   }
53
54   protected void tearDown() throws Exception JavaDoc {
55     super.tearDown();
56   }
57   
58   public void test1() {
59     Logger logger = LoggerFactory.getLogger("test1");
60     logger.debug("Hello world.");
61   }
62   
63   public void test2() {
64     Integer JavaDoc i1 = new Integer JavaDoc(1);
65     Integer JavaDoc i2 = new Integer JavaDoc(2);
66     Integer JavaDoc i3 = new Integer JavaDoc(3);
67     Exception JavaDoc e = new Exception JavaDoc("This is a test exception.");
68     Logger logger = LoggerFactory.getLogger("test2");
69     
70     logger.debug("Hello world 1.");
71     logger.debug("Hello world {}", i1);
72     logger.debug("val={} val={}", i1, i2);
73     logger.debug("val={} val={} val={}", new Object JavaDoc[]{i1, i2, i3});
74     
75     logger.debug("Hello world 2", e);
76     logger.info("Hello world 2.");
77  
78     
79     logger.warn("Hello world 3.");
80     logger.warn("Hello world 3", e);
81  
82   
83     logger.error("Hello world 4.");
84     logger.error("Hello world {}", new Integer JavaDoc(3));
85     logger.error("Hello world 4.", e);
86   }
87   
88   public void testNull() {
89     Logger logger = LoggerFactory.getLogger("testNull");
90     logger.debug(null);
91     logger.info(null);
92     logger.warn(null);
93     logger.error(null);
94     
95     Exception JavaDoc e = new Exception JavaDoc("This is a test exception.");
96     logger.debug(null, e);
97     logger.info(null, e);
98     logger.warn(null, e);
99     logger.error(null, e);
100   }
101   
102   public void testMarker() {
103     Logger logger = LoggerFactory.getLogger("testMarker");
104     Marker blue = MarkerFactory.getMarker("BLUE");
105     logger.debug(blue, "hello");
106     logger.info(blue, "hello");
107     logger.warn(blue, "hello");
108     logger.error(blue, "hello");
109     
110     logger.debug(blue, "hello {}", "world");
111     logger.info(blue, "hello {}", "world");
112     logger.warn(blue, "hello {}", "world");
113     logger.error(blue, "hello {}", "world");
114
115     logger.debug(blue, "hello {} and {} ", "world", "universe");
116     logger.info(blue, "hello {} and {} ", "world", "universe");
117     logger.warn(blue, "hello {} and {} ", "world", "universe");
118     logger.error(blue, "hello {} and {} ", "world", "universe");
119   }
120   
121   public void testMDC() {
122     MDC.put("k", "v");
123     assertNull(MDC.get("k"));
124     MDC.remove("k");
125     assertNull(MDC.get("k"));
126     MDC.clear();
127   }
128 }
129
Popular Tags