KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 24.08.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.apache.catalina.storeconfig;
8
9 import junit.framework.TestCase;
10
11 import org.apache.catalina.core.StandardContext;
12 import org.apache.catalina.core.StandardEngine;
13 import org.apache.catalina.core.StandardHost;
14 import org.apache.catalina.startup.ContextConfig;
15 import java.io.File JavaDoc ;
16
17 /**
18  * @author Peter Rossbach
19  *
20  */

21 public class StoreContextAppenderTest extends TestCase {
22
23     StoreContextAppender appender = new StoreContextAppender();
24
25     StandardContext context = new StandardContext();
26
27     StandardHost host = new StandardHost();
28
29     /*
30      * setup default Engine, Host and Context
31      *
32      * @see junit.framework.TestCase#setUp()
33      */

34     protected void setUp() throws Exception JavaDoc {
35         host.setName("localhost");
36         context.setParent(host);
37         StandardEngine engine = new StandardEngine();
38         engine.setName("Catalina");
39         host.setParent(engine);
40         super.setUp();
41     }
42
43     public void testWorkDirManager() {
44         context.setPath("/manager");
45         String JavaDoc defaultDir = appender.getDefaultWorkDir(context);
46         assertEquals("work\\Catalina\\localhost\\manager", defaultDir);
47
48     }
49
50     public void testWorkDirRoot() {
51         context.setPath("");
52         String JavaDoc defaultDir = appender.getDefaultWorkDir(context);
53         assertEquals("work\\Catalina\\localhost\\_", defaultDir);
54     }
55
56     public void testHostWorkDirRoot() {
57         context.setPath("");
58         host.setWorkDir("hostwork");
59         String JavaDoc defaultDir = appender.getDefaultWorkDir(context);
60         assertEquals("hostwork\\_", defaultDir);
61     }
62
63     public void testIsPrintValueDefault() {
64         StandardContext context2 = new StandardContext();
65         context.setPath("");
66         context.setWorkDir("work\\Catalina\\localhost\\_");
67         assertFalse(appender.isPrintValue(context, context2, "workDir", null));
68     }
69
70     public void testIsPrintValue() {
71         StandardContext context2 = new StandardContext();
72         context.setPath("");
73         context.setWorkDir("C:\\work\\Catalina\\localhost\\_");
74         assertTrue(appender.isPrintValue(context, context2, "workDir", null));
75     }
76
77     public void testHostIsPrintValuedefault() {
78         StandardContext context2 = new StandardContext();
79         context.setPath("");
80         host.setWorkDir("hostwork");
81         context.setWorkDir("hostwork\\_");
82         assertFalse(appender.isPrintValue(context, context2, "workDir", null));
83     }
84
85     public void _testDefaultInstance() throws Exception JavaDoc {
86         assertTrue(context.getCookies());
87         assertFalse(context.getReloadable());
88         StandardContext defaultContext = (StandardContext) appender
89                 .defaultInstance(context);
90         assertFalse(defaultContext.getCookies());
91         assertTrue(defaultContext.getReloadable());
92         assertEquals(2, defaultContext.findLifecycleListeners().length);
93         assertTrue(defaultContext.findLifecycleListeners()[0] instanceof ContextConfig);
94         assertTrue(defaultContext.findLifecycleListeners()[1] instanceof InfoLifecycleListener);
95     }
96
97     public void _testDefaultInstanceWithoutOverride() throws Exception JavaDoc {
98         context.setOverride(true);
99         StandardContext defaultContext = (StandardContext) appender
100                 .defaultInstance(context);
101         assertEquals(0, defaultContext.findLifecycleListeners().length);
102
103     }
104     
105     public void testPath() throws Exception JavaDoc {
106         StandardContext defaultContext = (StandardContext) appender
107         .defaultInstance(context);
108         context.setPath("/myapps");
109         assertNull(context.getConfigFile());
110         StoreDescription desc = new StoreDescription();
111         desc.setExternalAllowed(true);
112         desc.setStoreSeparate(true);
113         assertTrue(appender.isPrintValue(context, defaultContext, "path", desc));
114         context.setConfigFile("conf/Catalina/locahost/myapps.xml");
115         assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
116         desc.setExternalAllowed(false);
117         assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
118         desc.setExternalAllowed(true);
119         desc.setStoreSeparate(false);
120         assertFalse(appender.isPrintValue(context, defaultContext, "path", desc));
121     }
122     
123     public void testDocBase() throws Exception JavaDoc {
124         StandardContext defaultContext = (StandardContext) appender
125         .defaultInstance(context);
126         context.setPath("/myapps");
127         context.setDocBase("myapps");
128         host.setAppBase("webapps");
129         assertFalse(appender.isPrintValue(context, defaultContext, "docBase", null));
130         context.setDocBase(System.getProperty("java.io.tmpdir") + "/myapps");
131         assertTrue(appender.isPrintValue(context, defaultContext, "docBase", null));
132         
133     }
134 }
Popular Tags