KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > storeconfig > StoreLoaderTest


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

16 package org.apache.catalina.storeconfig;
17
18 import java.io.IOException JavaDoc;
19 import java.io.StringReader JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.catalina.cluster.tcp.ReplicationTransmitter;
24 import org.apache.catalina.core.StandardContext;
25 import org.apache.catalina.core.StandardServer;
26 import org.apache.catalina.mbeans.ServerLifecycleListener;
27 import org.apache.tomcat.util.digester.Digester;
28 import org.xml.sax.SAXException JavaDoc;
29
30 /**
31  * @author Peter Rossbach
32  *
33  */

34 public class StoreLoaderTest extends TestCase {
35
36     public void testDigester() throws IOException JavaDoc, SAXException JavaDoc {
37         Digester digester = StoreLoader.createDigester();
38         String JavaDoc example = "<Registry name=\"Tomcat\" version=\"5.5.0\" encoding=\"UTF-8\" >"
39                 + " <Description "
40                 + " tag=\"Server\""
41                 + " standard=\"true\""
42                 + " default=\"true\""
43                 + " tagClass=\"org.apache.catalina.core.StandardServer\""
44                 + " storeFactoryClass=\"org.apache.catalina.storeconfig.StandardServerSF\">"
45                 + " </Description>" + "</Registry>";
46         StringReader JavaDoc reader = new StringReader JavaDoc(example);
47         StoreRegistry registry = (StoreRegistry) digester.parse(reader);
48         assertNotNull(registry);
49         assertEquals("Tomcat", registry.getName());
50         assertEquals("5.5.0", registry.getVersion());
51         StoreDescription desc = registry.findDescription(StandardServer.class);
52         assertNotNull(desc);
53         assertEquals("org.apache.catalina.core.StandardServer", desc
54                 .getTagClass());
55         assertEquals("Server", desc.getTag());
56     }
57
58     public void testLoadRegistry() {
59         StoreLoader loader = new StoreLoader();
60         loader.load();
61         StoreRegistry registry = loader.getRegistry();
62         assertNotNull(registry);
63         assertEquals("UTF-8", registry.getEncoding());
64         StoreDescription desc = registry.findDescription(StandardServer.class);
65         assertNotNull(desc);
66         assertEquals("org.apache.catalina.core.StandardServer", desc
67                 .getTagClass());
68         desc = registry.findDescription(StandardContext.class);
69         assertNotNull(desc);
70         assertEquals(StandardContext.class.getName(), desc.getTagClass());
71         assertTrue(desc.isStoreSeparate());
72         assertNotNull(desc.getStoreFactory());
73         assertEquals(registry, desc.getStoreFactory().getRegistry());
74         assertEquals(StandardContextSF.class, desc.getStoreFactory().getClass());
75         desc = registry
76                 .findDescription("org.apache.catalina.core.StandardServer.[ServerLifecycleListener]");
77         assertEquals(ServerLifecycleListener.class.getName(), desc
78                 .getTagClass());
79         desc = registry.findDescription(ReplicationTransmitter.class);
80         assertNotNull(desc);
81         assertEquals(ReplicationTransmitter.class.getName(), desc
82                 .getTagClass());
83         assertNotNull(desc.getStoreFactory());
84         assertEquals(ReplicationTransmitterStoreAppender.class, desc.getStoreFactory().getStoreAppender().getClass()
85                 );
86         
87     }
88 }
Popular Tags