View Javadoc

    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.xml;
    19
    20  import junit.framework.Test;
    21  import junit.framework.TestCase;
    22  import junit.framework.TestSuite;
    23  import org.apache.log4j.Logger;
    24  import org.apache.log4j.util.Compare;
    25
    26  public class CustomLevelTestCase extends TestCase {
    27
    28    static String TEMP = "output/temp";
    29
    30    Logger root;
    31    Logger logger;
    32
    33    public CustomLevelTestCase(String name) {
    34      super(name);
    35    }
    36
    37    public void setUp() {
    38      root = Logger.getRootLogger();
    39      logger = Logger.getLogger(CustomLevelTestCase.class);
    40    }
    41
    42    public void tearDown() {
    43      root.getLoggerRepository().resetConfiguration();
    44    }
    45
    46    public void test1() throws Exception {
    47      DOMConfigurator.configure("input/xml/customLevel1.xml");
    48      common();
    49      assertTrue(Compare.compare(TEMP, "witness/customLevel.1"));
    50    }
    51
    52    public void test2() throws Exception {
    53      DOMConfigurator.configure("input/xml/customLevel2.xml");
    54      common();
    55      assertTrue(Compare.compare(TEMP, "witness/customLevel.2"));
    56    }
    57
    58    public void test3() throws Exception {
    59      DOMConfigurator.configure("input/xml/customLevel3.xml");
    60      common();
    61      assertTrue(Compare.compare(TEMP, "witness/customLevel.3"));
    62    }
    63
    64    public void test4() throws Exception {
    65      DOMConfigurator.configure("input/xml/customLevel4.xml");
    66      common();
    67      assertTrue(Compare.compare(TEMP, "witness/customLevel.4"));
    68    }
    69
    70
    71    void common() {
    72      int i = 0;
    73      logger.debug("Message " + ++i);
    74      logger.info ("Message " + ++i);
    75      logger.warn ("Message " + ++i);
    76      logger.error("Message " + ++i);
    77      logger.log(XLevel.TRACE, "Message " + ++i);
    78    }
    79
    80    public static Test suite() {
    81      TestSuite suite = new TestSuite();
    82      suite.addTest(new CustomLevelTestCase("test1"));
    83      suite.addTest(new CustomLevelTestCase("test2"));
    84      suite.addTest(new CustomLevelTestCase("test3"));
    85      suite.addTest(new CustomLevelTestCase("test4"));
    86      return suite;
    87    }
    88
    89  }