FileDocCategorySizeDatePackage
PropertyConfiguratorTest.javaAPI DocApache log4j 1.2.153566Sat Aug 25 00:09:34 BST 2007org.apache.log4j

PropertyConfiguratorTest

public class PropertyConfiguratorTest extends TestCase
Test property configurator.

Fields Summary
Constructors Summary
public PropertyConfiguratorTest(String testName)

        super(testName);
    
Methods Summary
public voidtestBadUnicodeEscape()
Test for bug 40944. Did not catch IllegalArgumentException on Properties.load and close input stream.

throws
IOException if IOException creating properties file.

        String fileName = "output/badescape.properties";
        FileWriter writer = new FileWriter(fileName);
        writer.write("log4j.rootLogger=\\uXX41");
        writer.close();
        PropertyConfigurator.configure(fileName);
        File file = new File(fileName);
        assertTrue(file.delete()) ;
        assertFalse(file.exists());
    
public voidtestReset()
Test processing of log4j.reset property, see bug 17531.

        VectorAppender appender = new VectorAppender();
        appender.setName("A1");
        Logger.getRootLogger().addAppender(appender);
        Properties props = new Properties();
        props.put("log4j.reset", "true");
        PropertyConfigurator.configure(props);
        assertNull(Logger.getRootLogger().getAppender("A1"));
        LogManager.resetConfiguration();
    
public voidtestURL()
Test for bug 40944. configure(URL) never closed opened stream.

throws
IOException if IOException creating properties file.

        File file = new File("output/unclosed.properties");
        FileWriter writer = new FileWriter(file);
        writer.write("log4j.rootLogger=debug");
        writer.close();
        URL url = file.toURL();
        PropertyConfigurator.configure(url);
        assertTrue(file.delete());
        assertFalse(file.exists());
    
public voidtestURLBadEscape()
Test for bug 40944. configure(URL) did not catch IllegalArgumentException and did not close stream.

throws
IOException if IOException creating properties file.

        File file = new File("output/urlbadescape.properties");
        FileWriter writer = new FileWriter(file);
        writer.write("log4j.rootLogger=\\uXX41");
        writer.close();
        URL url = file.toURL();
        PropertyConfigurator.configure(url);
        assertTrue(file.delete());
        assertFalse(file.exists());