1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.log4j.customLogger;
19  
20  import org.apache.log4j.xml.DOMConfigurator;
21  import org.apache.log4j.util.*;
22  
23  import junit.framework.TestCase;
24  import junit.framework.TestSuite;
25  import junit.framework.Test;
26  
27  /**
28     Tests handling of custom loggers.
29     
30     @author Ceki Gülcü
31  */
32  public class XLoggerTestCase extends TestCase {
33  
34    static String FILTERED = "output/filtered";
35    static XLogger logger = (XLogger) XLogger.getLogger(XLoggerTestCase.class);
36  
37    public XLoggerTestCase(String name){
38      super(name);
39    }
40  
41    public void tearDown() {
42      logger.getLoggerRepository().resetConfiguration();
43    }
44  
45    public void test1()  throws Exception  { common(1); }
46    public void test2()  throws Exception  { common(2); }
47  
48    void common(int number) throws Exception {
49      DOMConfigurator.configure("input/xml/customLogger"+number+".xml");
50  
51      int i = -1;
52  
53      logger.trace("Message " + ++i);
54      logger.debug("Message " + ++i);
55      logger.warn ("Message " + ++i);
56      logger.error("Message " + ++i);
57      logger.fatal("Message " + ++i);
58      Exception e = new Exception("Just testing");
59      logger.debug("Message " + ++i, e);
60  
61      Transformer.transform(
62        "output/temp", FILTERED,
63        new Filter[] {
64          new LineNumberFilter(), new SunReflectFilter(),
65          new JunitTestRunnerFilter()
66        });
67      assertTrue(Compare.compare(FILTERED, "witness/customLogger."+number));
68  
69    }
70  
71    public static Test suite() {
72      TestSuite suite = new TestSuite();
73      suite.addTest(new XLoggerTestCase("test1"));
74      suite.addTest(new XLoggerTestCase("test2"));
75      return suite;
76    }
77  }