1 17 18 package org.apache.avalon.fortress.util.test; 19 20 import junit.framework.TestCase; 21 import org.apache.avalon.framework.configuration.DefaultConfiguration; 22 import org.apache.avalon.framework.context.DefaultContext; 23 import org.apache.avalon.framework.logger.NullLogger; 24 import org.apache.avalon.framework.parameters.Parameters; 25 import org.apache.avalon.framework.service.DefaultServiceManager; 26 27 34 public final class ComponentTestCase 35 extends TestCase 36 { 37 public ComponentTestCase( String test ) 38 { 39 super( test ); 40 } 41 42 public void testCorrectLifecycle() 43 throws Exception 44 { 45 final FullLifecycleComponent component = new FullLifecycleComponent(); 46 component.enableLogging( new NullLogger() ); 47 component.contextualize( new DefaultContext() ); 48 component.service( new DefaultServiceManager() ); 49 component.configure( new DefaultConfiguration( "", "" ) ); 50 component.parameterize( new Parameters() ); 51 component.initialize(); 52 component.start(); 53 component.suspend(); 54 component.resume(); 55 component.stop(); 56 component.dispose(); 57 } 58 59 public void testMissingLogger() 60 throws Exception 61 { 62 FullLifecycleComponent component = new FullLifecycleComponent(); 63 64 try 65 { 66 component.contextualize( new DefaultContext() ); 67 } 68 catch ( Exception e ) 69 { 70 return; 71 } 72 fail( "Did not detect missing logger" ); 73 } 74 75 public void testOutOfOrderInitialize() 76 throws Exception 77 { 78 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 79 component.enableLogging( new NullLogger() ); 80 component.contextualize( new DefaultContext() ); 81 component.service( new DefaultServiceManager() ); 82 try 83 { 84 component.initialize(); 85 component.parameterize( new Parameters() ); 86 } 87 catch ( Exception e ) 88 { 89 return; 90 } 91 fail( "Did not detect out of order initialization" ); 92 } 93 94 public void testOutOfOrderDispose() 95 throws Exception 96 { 97 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 98 component.enableLogging( new NullLogger() ); 99 component.contextualize( new DefaultContext() ); 100 component.service( new DefaultServiceManager() ); 101 component.configure( new DefaultConfiguration( "", "" ) ); 102 component.parameterize( new Parameters() ); 103 component.initialize(); 104 component.start(); 105 component.suspend(); 106 component.resume(); 107 108 try 109 { 110 component.dispose(); 111 component.stop(); 112 } 113 catch ( Exception e ) 114 { 115 return; 116 } 117 fail( "Did not detect out of order disposal" ); 118 } 119 120 public void testDoubleAssignOfLogger() 121 { 122 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 123 try 124 { 125 component.enableLogging( new NullLogger() ); 126 component.enableLogging( new NullLogger() ); 127 } 128 catch ( Exception e ) 129 { 130 return; 132 } 133 134 fail( "Did not detect double assignment of Logger" ); 135 } 136 137 public void testDoubleAssignOfContext() 138 { 139 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 140 component.enableLogging( new NullLogger() ); 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 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 159 component.enableLogging( new NullLogger() ); 160 component.contextualize( new DefaultContext() ); 161 component.service( new DefaultServiceManager() ); 162 component.configure( new DefaultConfiguration( "", "" ) ); 163 164 try 165 { 166 component.parameterize( new Parameters() ); 167 component.parameterize( new Parameters() ); 168 } 169 catch ( Exception e ) 170 { 171 return; 173 } 174 175 fail( "Did not detect double assignment of Parameters" ); 176 } 177 178 public void testDoubleAssignOfConfiguration() throws Exception 179 { 180 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 181 component.enableLogging( new NullLogger() ); 182 component.contextualize( new DefaultContext() ); 183 component.service( new DefaultServiceManager() ); 184 try 185 { 186 component.configure( new DefaultConfiguration( "", "" ) ); 187 component.configure( new DefaultConfiguration( "", "" ) ); 188 } 189 catch ( Exception e ) 190 { 191 return; 193 } 194 195 fail( "Did not detect double assignment of Configuration" ); 196 } 197 198 public void testDoubleAssignOfComponentManger() 199 throws Exception 200 { 201 final org.apache.avalon.fortress.util.test.FullLifecycleComponent component = new org.apache.avalon.fortress.util.test.FullLifecycleComponent(); 202 component.enableLogging( new NullLogger() ); 203 component.contextualize( new DefaultContext() ); 204 try 205 { 206 component.service( new DefaultServiceManager() ); 207 component.service( new DefaultServiceManager() ); 208 } 209 catch ( Exception e ) 210 { 211 return; 213 } 214 215 fail( "Did not detect double assignment of ComponentLocator" ); 216 } 217 } 218 | Popular Tags |