KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > logging > data > test > CategoryDirectiveTestCase


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
27  * CategoryTestCase does XYZ
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $ Revision: 1.1 $
31  */

32 public class CategoryDirectiveTestCase extends TestCase
33 {
34     public CategoryDirectiveTestCase( String JavaDoc name )
35     {
36         super( name );
37     }
38
39     public void testCategory()
40     {
41         String JavaDoc catName = "name";
42         CategoryDirective cat = new CategoryDirective(catName);
43
44         testCategory( cat, catName, null, null );
45     }
46
47     public void testLogPriority()
48     {
49         String JavaDoc catName = "name";
50         String JavaDoc 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 JavaDoc name = "name";
74         String JavaDoc priority = CategoryDirective.DEBUG;
75         String JavaDoc 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 JavaDoc name, String JavaDoc priority, String JavaDoc 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 JavaDoc
89     {
90         File file = new File("name.test");
91         String JavaDoc name = "name";
92         String JavaDoc priority = CategoryDirective.WARN;
93         String JavaDoc 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