1 4 5 package org.objectweb.util.monolog; 6 7 import org.objectweb.util.monolog.api.BasicLevel; 8 import org.objectweb.util.monolog.api.LevelFactory; 9 import org.objectweb.util.monolog.api.Level; 10 import junit.framework.TestCase; 11 import junit.textui.TestRunner; 12 13 18 public class TestLevel extends TestCase { 19 20 24 public static final String [] SETTER_METHODS = {"setLevelFactoryClassName"}; 25 26 protected LevelFactory lf = null; 27 28 private Level l = null; 29 30 public TestLevel() { 31 super(""); 32 } 33 34 38 public void setLevelFactoryClassName(String lfcn) { 39 try { 40 lf = (LevelFactory) Class.forName(lfcn).newInstance(); 41 } 42 catch (ClassCastException e) { 43 throw new UnsupportedOperationException ( 44 "The specified class is not a Level factory: " + lfcn); 45 } 46 catch (Exception e) { 47 throw new UnsupportedOperationException ( 48 "Level factory class is not availlable: " + lfcn); 49 } 50 } 51 52 60 public static void main(String args[]) { 61 if (args.length < 1) { 62 System.out.println("Syntax error !"); 63 System.out.println("java TestLevel <level factory class name>"); 64 System.exit(12); 65 } 66 Object [] params = {args[0]}; 67 try { 68 TestSuite suite = 69 new TestSuite(TestLevel.class, SETTER_METHODS, params); 70 TestRunner.run(suite); 71 } 72 catch (Exception e) { 73 e.printStackTrace(); 74 } 75 } 76 77 public static TestSuite getTestSuite(String lfcn) { 78 Object [] params = {lfcn}; 79 try { 80 return new TestSuite(TestLevel.class, SETTER_METHODS, params); 81 } 82 catch (Exception e) { 83 e.printStackTrace(); 84 return null; 85 } 86 } 87 88 91 95 public void testInterLevelDef() { 96 assertEquals("Predefined level unreconized", 97 BasicLevel.DEBUG, 98 lf.getLevel("DEBUG").getIntValue()); 99 l = lf.defineLevel("MY_LEVEL", "DEBUG + 1"); 100 assertNotNull("Null level", l); 101 assertEquals("intermediate level definition", 102 BasicLevel.DEBUG + 1, 103 l.getIntValue()); 104 } 105 106 114 public void testInterLevelDefWithOther() { 115 lf.defineLevel("MY_LEVEL", "DEBUG + 1"); 116 l = lf.defineLevel("MY_LEVEL2", "MY_LEVEL + 1"); 117 assertEquals( 118 "intermediate level definition based on another intermediate level", 119 BasicLevel.DEBUG + 2, 120 l.getIntValue()); 121 } 122 123 127 public void testInterLevelDefByMinus() { 128 l = lf.defineLevel("TOTO", "DEBUG - 1"); 129 assertEquals( 130 "intermediate level definition minus operator", 131 BasicLevel.DEBUG - 1, 132 l.getIntValue()); 133 } 134 135 140 public void testInterLevelDefWithFigures() { 141 l = lf.defineLevel("TOTO2", "INFO +156 "); 142 assertEquals( 143 "intermediate level definition, number with several figures", 144 BasicLevel.INFO + 156, 145 l.getIntValue()); 146 } 147 148 153 public void testInterLevelWithLowerCase() { 154 l = lf.defineLevel("TOTO3", " InFO + 1 "); 155 assertEquals( 156 "intermediate level definition, level name with lower case", 157 BasicLevel.INFO + 1, 158 l.getIntValue()); 159 } 160 161 165 public void testInterLevelJustNb() { 166 l = lf.defineLevel("TOTO4", "23455"); 167 assertEquals( 168 "intermediate level definition, level value is just a number", 169 23455, 170 l.getIntValue()); 171 l = lf.defineLevel("TOTO7", 23455); 172 assertEquals( 173 "intermediate level definition, level value is just a number", 174 23455, 175 l.getIntValue()); 176 177 } 178 179 183 public void testInterLevelJustOther() { 184 lf.defineLevel("TOTO3", " InFO + 1 "); 185 l = lf.defineLevel("TOTO5", "TOTO3"); 186 assertEquals( 187 "intermediate level definition, level value is just another intermediate level", 188 BasicLevel.INFO + 1, 189 l.getIntValue()); 190 } 191 192 } 193 | Popular Tags |