KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrintWriter JavaDoc;
19 import java.io.StringWriter JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.catalina.Loader;
24 import org.apache.catalina.loader.WebappLoader;
25 import org.apache.catalina.storeconfig.LoaderSF;
26 import org.apache.catalina.storeconfig.StoreDescription;
27 import org.apache.catalina.storeconfig.StoreRegistry;
28
29 /**
30  * @author Peter Rossbach
31  *
32  */

33 public class LoaderSFTest extends TestCase {
34     StoreRegistry registry;
35
36     StringWriter JavaDoc writer = new StringWriter JavaDoc();
37
38     PrintWriter JavaDoc pWriter = new PrintWriter JavaDoc(writer);
39
40     Loader loader;
41
42     LoaderSF factory;
43
44     StoreDescription desc;
45
46     /*
47      * create Registry and register Loader
48      *
49      * @see junit.framework.TestCase#setUp()
50      */

51     protected void setUp() throws Exception JavaDoc {
52
53         super.setUp();
54         registry = new StoreRegistry();
55         desc = DescriptorHelper.registerDescriptor(null, registry,
56                 WebappLoader.class.getName(), "Loader", WebappLoader.class
57                         .getName(), "org.apache.catalina.storeconfig.LoaderSF",
58                 false, false);
59         factory = (LoaderSF) desc.getStoreFactory();
60         loader = new WebappLoader();
61
62     }
63
64     public void testManagerNonStandardStore() throws Exception JavaDoc {
65         assertTrue(factory.isDefaultLoader(loader));
66         loader.setDelegate(true);
67         assertFalse(factory.isDefaultLoader(loader));
68         String JavaDoc aspectedResult = "<Loader className=\"org.apache.catalina.loader.WebappLoader\""
69                 + LF.LINE_SEPARATOR
70                 + " delegate=\"true\"/>"
71                 + LF.LINE_SEPARATOR;
72         check(aspectedResult);
73     }
74
75     public void testStoreEmpty() throws Exception JavaDoc {
76         assertTrue(factory.isDefaultLoader(loader));
77         String JavaDoc aspectedResult = "";
78         check(aspectedResult);
79     }
80
81     protected void check(String JavaDoc aspectedResult) throws Exception JavaDoc {
82         factory.store(pWriter, -2, loader);
83         assertEquals(aspectedResult, writer.toString());
84     }
85
86 }
Popular Tags