1 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 ; 16 17 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 34 protected void setUp() throws Exception { 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 defaultDir = appender.getDefaultWorkDir(context); 46 assertEquals("work\\Catalina\\localhost\\manager", defaultDir); 47 48 } 49 50 public void testWorkDirRoot() { 51 context.setPath(""); 52 String 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 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 { 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 { 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 { 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 { 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 |