1 8 package org.apache.avalon.excalibur.util.test; 9 10 import junit.framework.TestCase; 11 import org.apache.avalon.framework.component.ComponentException; 12 import org.apache.avalon.framework.component.DefaultComponentManager; 13 import org.apache.avalon.framework.configuration.ConfigurationException; 14 import org.apache.avalon.framework.configuration.DefaultConfiguration; 15 import org.apache.avalon.framework.context.ContextException; 16 import org.apache.avalon.framework.context.DefaultContext; 17 import org.apache.avalon.framework.logger.LogKitLogger; 18 import org.apache.avalon.framework.parameters.ParameterException; 19 import org.apache.avalon.framework.parameters.Parameters; 20 import org.apache.log.Hierarchy; 21 22 29 public final class ComponentTestCase 30 extends TestCase 31 { 32 public ComponentTestCase( String test ) 33 { 34 super( test ); 35 } 36 37 public void testCorrectLifecycle() 38 throws Exception 39 { 40 FullLifecycleComponent component = new FullLifecycleComponent(); 41 42 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 43 component.contextualize(new DefaultContext()); 44 component.compose(new DefaultComponentManager()); 45 component.configure(new DefaultConfiguration("", "")); 46 component.parameterize(new Parameters()); 47 component.initialize(); 48 component.start(); 49 component.suspend(); 50 component.resume(); 51 component.stop(); 52 component.dispose(); 53 } 54 55 public void testMissingLogger() 56 throws Exception 57 { 58 FullLifecycleComponent component = new FullLifecycleComponent(); 59 60 try 61 { 62 component.contextualize(new DefaultContext()); 63 } 64 catch ( Exception e ) 65 { 66 return; 67 } 68 fail("Did not detect missing logger"); 69 } 70 71 public void testOutOfOrderInitialize() 72 throws Exception 73 { 74 FullLifecycleComponent component = new FullLifecycleComponent(); 75 76 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 77 component.contextualize(new DefaultContext()); 78 component.compose(new DefaultComponentManager()); 79 try 80 { 81 component.initialize(); 82 component.parameterize(new Parameters()); 83 } 84 catch ( Exception e ) 85 { 86 return; 87 } 88 fail("Did not detect out of order initialization"); 89 } 90 91 public void testOutOfOrderDispose() 92 throws Exception 93 { 94 FullLifecycleComponent component = new FullLifecycleComponent(); 95 96 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 97 component.contextualize(new DefaultContext()); 98 component.compose(new DefaultComponentManager()); 99 component.configure(new DefaultConfiguration("", "")); 100 component.parameterize(new Parameters()); 101 component.initialize(); 102 component.start(); 103 component.suspend(); 104 component.resume(); 105 106 try 107 { 108 component.dispose(); 109 component.stop(); 110 } 111 catch ( Exception e ) 112 { 113 return; 114 } 115 fail("Did not detect out of order disposal"); 116 } 117 118 public void testDoubleAssignOfLogger() 119 { 120 FullLifecycleComponent component = new FullLifecycleComponent(); 121 122 try 123 { 124 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 125 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 126 } 127 catch (Exception e) 128 { 129 return; 131 } 132 133 fail("Did not detect double assignment of Logger"); 134 } 135 136 public void testDoubleAssignOfContext() 137 { 138 FullLifecycleComponent component = new FullLifecycleComponent(); 139 140 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 141 try 142 { 143 component.contextualize(new DefaultContext()); 144 component.contextualize(new DefaultContext()); 145 } 146 catch (Exception e) 147 { 148 return; 150 } 151 152 fail("Did not detect double assignment of Context"); 153 } 154 155 public void testDoubleAssignOfParameters() 156 throws Exception 157 { 158 FullLifecycleComponent component = new FullLifecycleComponent(); 159 160 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 161 component.contextualize(new DefaultContext()); 162 component.compose(new DefaultComponentManager()); 163 component.configure(new DefaultConfiguration("", "")); 164 165 try 166 { 167 component.parameterize(new Parameters()); 168 component.parameterize(new Parameters()); 169 } 170 catch (Exception e) 171 { 172 return; 174 } 175 176 fail("Did not detect double assignment of Parameters"); 177 } 178 179 public void testDoubleAssignOfConfiguration() throws Exception 180 { 181 FullLifecycleComponent component = new FullLifecycleComponent(); 182 183 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 184 component.contextualize(new DefaultContext()); 185 component.compose(new DefaultComponentManager()); 186 try 187 { 188 component.configure(new DefaultConfiguration("", "")); 189 component.configure(new DefaultConfiguration("", "")); 190 } 191 catch (Exception e) 192 { 193 return; 195 } 196 197 fail("Did not detect double assignment of Configuration"); 198 } 199 200 public void testDoubleAssignOfComponentManger() 201 throws Exception 202 { 203 FullLifecycleComponent component = new FullLifecycleComponent(); 204 205 component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""))); 206 component.contextualize(new DefaultContext()); 207 try 208 { 209 component.compose(new DefaultComponentManager()); 210 component.compose(new DefaultComponentManager()); 211 } 212 catch (Exception e) 213 { 214 return; 216 } 217 218 fail("Did not detect double assignment of ComponentManager"); 219 } 220 } 221 | Popular Tags |