HierarchyThresholdTestCase xref

    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;
    19
    20  import junit.framework.TestCase;
    21  import junit.framework.TestSuite;
    22  import junit.framework.Test;
    23
    24  import org.apache.log4j.util.Compare;
    25  import org.apache.log4j.xml.XLevel;
    26
    27  /**
    28     Test the configuration of the hierarchy-wide threshold.
    29
    30     @author  Ceki G&uuml;lc&uuml;
    31  */
    32  public class HierarchyThresholdTestCase extends TestCase {
    33
    34    static String TEMP = "output/temp";
    35    static Logger logger = Logger.getLogger(HierarchyThresholdTestCase.class);
    36
    37    public HierarchyThresholdTestCase(String name) {
    38      super(name);
    39    }
    40
    41    public void setUp() {
    42    }
    43
    44    public void tearDown() {
    45      System.out.println("Tearing down test case.");
    46      logger.getLoggerRepository().resetConfiguration();
    47    }
    48
    49    public void test1() throws Exception {
    50      PropertyConfigurator.configure("input/hierarchyThreshold1.properties");
    51      common();
    52      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.1"));
    53    }
    54
    55    public void test2() throws Exception {
    56      PropertyConfigurator.configure("input/hierarchyThreshold2.properties");
    57      common();
    58      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.2"));
    59    }
    60
    61    public void test3() throws Exception {
    62      PropertyConfigurator.configure("input/hierarchyThreshold3.properties");
    63      common();
    64      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.3"));
    65    }
    66
    67    public void test4() throws Exception {
    68      PropertyConfigurator.configure("input/hierarchyThreshold4.properties");
    69      common();
    70      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.4"));
    71    }
    72
    73    public void test5() throws Exception {
    74      PropertyConfigurator.configure("input/hierarchyThreshold5.properties");
    75      common();
    76      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.5"));
    77    }
    78
    79    public void test6() throws Exception {
    80      PropertyConfigurator.configure("input/hierarchyThreshold6.properties");
    81      common();
    82      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.6"));
    83    }
    84
    85    public void test7() throws Exception {
    86      PropertyConfigurator.configure("input/hierarchyThreshold7.properties");
    87      common();
    88      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.7"));
    89    }
    90
    91    public void test8() throws Exception {
    92      PropertyConfigurator.configure("input/hierarchyThreshold8.properties");
    93      common();
    94      assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.8"));
    95    }
    96
    97
    98    static
    99    void common() {
    100     String oldThreadName = Thread.currentThread().getName();
    101     Thread.currentThread().setName("main");
    102
    103     logger.log(XLevel.TRACE, "m0");
    104     logger.debug("m1");
    105     logger.info("m2");
    106     logger.warn("m3");
    107     logger.error("m4");
    108     logger.fatal("m5");
    109
    110     Thread.currentThread().setName(oldThreadName);
    111   }
    112
    113   public static Test suite() {
    114     TestSuite suite = new TestSuite();
    115     suite.addTest(new HierarchyThresholdTestCase("test1"));
    116     suite.addTest(new HierarchyThresholdTestCase("test2"));
    117     suite.addTest(new HierarchyThresholdTestCase("test3"));
    118     suite.addTest(new HierarchyThresholdTestCase("test4"));
    119     suite.addTest(new HierarchyThresholdTestCase("test5"));
    120     suite.addTest(new HierarchyThresholdTestCase("test6"));
    121     suite.addTest(new HierarchyThresholdTestCase("test7"));
    122     suite.addTest(new HierarchyThresholdTestCase("test8"));
    123     return suite;
    124   }
    125 }