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