FileDocCategorySizeDatePackage
OptionConverterTestCase.javaAPI DocApache log4j 1.2.154600Sat Aug 25 00:09:32 BST 2007org.apache.log4j.helpers

OptionConverterTestCase

public class OptionConverterTestCase extends TestCase
Test variable substitution code.
author
Ceki Gülcü
since
1.0

Fields Summary
Properties
props
Constructors Summary
public OptionConverterTestCase(String name)

    super(name);
  
Methods Summary
public voidsetUp()

    props = new Properties();
    props.put("TOTO", "wonderful");
    props.put("key1", "value1");
    props.put("key2", "value2");
    System.setProperties(props);


  
public static junit.framework.Testsuite()

    TestSuite suite = new TestSuite();
    suite.addTest(new OptionConverterTestCase("varSubstTest5"));
    suite.addTest(new OptionConverterTestCase("varSubstTest1"));
    suite.addTest(new OptionConverterTestCase("varSubstTest2"));
    suite.addTest(new OptionConverterTestCase("varSubstTest3"));
    suite.addTest(new OptionConverterTestCase("varSubstTest4"));


    suite.addTest(new OptionConverterTestCase("toLevelTest1"));
    suite.addTest(new OptionConverterTestCase("toLevelTest2"));
    suite.addTest(new OptionConverterTestCase("toLevelTest3"));
    suite.addTest(new OptionConverterTestCase("toLevelTest4"));
    suite.addTest(new OptionConverterTestCase("toLevelTest5"));
    return suite;
  
public voidtearDown()

    props = null;
  
public voidtoLevelTest1()

    String val = "INFO";
    Level p = OptionConverter.toLevel(val, null);
    assertEquals(p, Level.INFO);
  
public voidtoLevelTest2()

    String val = "INFO#org.apache.log4j.xml.XLevel";
    Level p = OptionConverter.toLevel(val, null);
    assertEquals(p, Level.INFO);
  
public voidtoLevelTest3()

    String val = "TRACE#org.apache.log4j.xml.XLevel";
    Level p = OptionConverter.toLevel(val, null);    
    assertEquals(p, XLevel.TRACE);
  
public voidtoLevelTest4()

    String val = "TR#org.apache.log4j.xml.XLevel";
    Level p = OptionConverter.toLevel(val, null);    
    assertEquals(p, null);
  
public voidtoLevelTest5()

    String val = "INFO#org.apache.log4j.xml.TOTO";
    Level p = OptionConverter.toLevel(val, null);    
    assertEquals(p, null);
  
public voidvarSubstTest1()

    String r;

    r = OptionConverter.substVars("hello world.", null);
    assertEquals("hello world.", r);
    
    r = OptionConverter.substVars("hello ${TOTO} world.", null);
    
    assertEquals("hello wonderful world.", r);
  
public voidvarSubstTest2()

    String r;

    r = OptionConverter.substVars("Test2 ${key1} mid ${key2} end.", null);
    assertEquals("Test2 value1 mid value2 end.", r);
  
public voidvarSubstTest3()

    String r;

    r = OptionConverter.substVars(
				     "Test3 ${unset} mid ${key1} end.", null);
    assertEquals("Test3  mid value1 end.", r);
  
public voidvarSubstTest4()

    String res;
    String val = "Test4 ${incomplete ";
    try {
      res = OptionConverter.substVars(val, null);
    }
    catch(IllegalArgumentException e) {
      String errorMsg = e.getMessage();
      //System.out.println('['+errorMsg+']');
      assertEquals('""+val
		   + "\" has no closing brace. Opening brace at position 6.", 
		   errorMsg);
    }
  
public voidvarSubstTest5()

    Properties props = new Properties();
    props.put("p1", "x1");
    props.put("p2", "${p1}");
    String res = OptionConverter.substVars("${p2}", props);
    System.out.println("Result is ["+res+"].");
    assertEquals(res, "x1");