1 17 18 package org.apache.avalon.logging.data.test; 19 20 import junit.framework.TestCase; 21 22 import org.apache.avalon.logging.data.CategoryDirective; 23 24 import java.io.*; 25 26 32 public class CategoryDirectiveTestCase extends TestCase 33 { 34 public CategoryDirectiveTestCase( String name ) 35 { 36 super( name ); 37 } 38 39 public void testCategory() 40 { 41 String catName = "name"; 42 CategoryDirective cat = new CategoryDirective(catName); 43 44 testCategory( cat, catName, null, null ); 45 } 46 47 public void testLogPriority() 48 { 49 String catName = "name"; 50 String priority = CategoryDirective.DEBUG; 51 CategoryDirective cat = new CategoryDirective( catName, priority); 52 53 testCategory( cat, catName, priority, null ); 54 55 priority = CategoryDirective.ERROR; 56 cat = new CategoryDirective( catName, priority ); 57 58 testCategory( cat, catName, priority, null ); 59 60 priority = CategoryDirective.INFO; 61 cat = new CategoryDirective( catName, priority ); 62 63 testCategory( cat, catName, priority, null ); 64 65 priority = CategoryDirective.WARN; 66 cat = new CategoryDirective( catName, priority ); 67 68 testCategory( cat, catName, priority, null ); 69 } 70 71 public void testLogTarget() 72 { 73 String name = "name"; 74 String priority = CategoryDirective.DEBUG; 75 String target = "test"; 76 CategoryDirective cat = new CategoryDirective( name, priority, target); 77 78 testCategory( cat, name, priority, target ); 79 } 80 81 protected void testCategory( CategoryDirective cat, String name, String priority, String target ) 82 { 83 assertEquals( name, cat.getName() ); 84 assertEquals( priority, cat.getPriority() ); 85 assertEquals( target, cat.getTarget() ); 86 } 87 88 public void testSerialization() throws IOException, ClassNotFoundException 89 { 90 File file = new File("name.test"); 91 String name = "name"; 92 String priority = CategoryDirective.WARN; 93 String target = "test"; 94 95 CategoryDirective original = new CategoryDirective( name, priority, target ); 96 97 testCategory( original, name, priority, target ); 98 99 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); 100 oos.writeObject(original); 101 oos.close(); 102 103 ObjectInputStream ois = new ObjectInputStream( new FileInputStream(file)); 104 CategoryDirective serialized = (CategoryDirective)ois.readObject(); 105 ois.close(); 106 107 file.delete(); 108 109 testCategory( serialized, name, priority, target ); 110 111 assertEquals( original, serialized ); 112 assertEquals( original.hashCode(), serialized.hashCode() ); 113 } 114 } 115 | Popular Tags |