KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.logging.data.CategoryDirective;
21 import org.apache.avalon.logging.data.CategoriesDirective;
22
23 import java.io.*;
24
25 /**
26  * CategoriesDirectiveTestCase.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version CVS $ Revision: 1.1 $
30  */

31 public class CategoriesDirectiveTestCase extends CategoryDirectiveTestCase
32 {
33     public CategoriesDirectiveTestCase( String JavaDoc name )
34     {
35         super( name );
36     }
37
38     public void testCategories()
39     {
40         String JavaDoc catName = "name";
41         CategoriesDirective cat =
42           new CategoriesDirective(
43             catName, null, null, new CategoryDirective[0] );
44         testCategory( cat, catName, null, null );
45     }
46
47     public void testSerialization() throws IOException, ClassNotFoundException JavaDoc
48     {
49         File file = new File("name.test");
50         String JavaDoc name = "name";
51         String JavaDoc priority = CategoryDirective.WARN;
52         String JavaDoc target = "test";
53
54         CategoriesDirective original =
55           new CategoriesDirective( name, priority, target, new CategoryDirective[0] );
56
57         testCategory( original, name, priority, target );
58
59         ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
60         oos.writeObject(original);
61         oos.close();
62
63         ObjectInputStream ois = new ObjectInputStream( new FileInputStream(file));
64         CategoriesDirective serialized = (CategoriesDirective)ois.readObject();
65         ois.close();
66
67         file.delete();
68
69         testCategory( serialized, name, priority, target );
70
71         assertEquals( original, serialized );
72         assertEquals( original.hashCode(), serialized.hashCode() );
73     }
74 }
75
Popular Tags