1 64 65 package com.jcorporate.expresso.kernel.util.test; 66 67 import com.jcorporate.expresso.kernel.Containable; 68 import com.jcorporate.expresso.kernel.ExpressoComponent; 69 import com.jcorporate.expresso.kernel.RootContainerInterface; 70 import com.jcorporate.expresso.kernel.SystemFactory; 71 import com.jcorporate.expresso.kernel.digester.ComponentConfig; 72 import com.jcorporate.expresso.kernel.exception.ConfigurationException; 73 import com.jcorporate.expresso.kernel.metadata.ComponentMetadata; 74 import com.jcorporate.expresso.kernel.util.LocatorUtils; 75 import com.jcorporate.expresso.services.test.TestSystemInitializer; 76 import junit.framework.TestCase; 77 78 81 public class TestLocatorUtils extends TestCase { 82 83 public TestLocatorUtils(String _name) { 84 super(_name); 85 } 86 87 RootContainerInterface globalContainer = null; 88 89 92 protected void setUp() { 93 try { 94 globalContainer = SystemFactory.buildExpressoComponentSystem( 95 this.getClass().getResource( 96 "/com/jcorporate/expresso/kernel/management/test/Test1ExpressoServices.xml"), 97 this.getClass().getResource("/com/jcorporate/expresso/kernel/management/test/TestLog4jConfig.xml"), 98 TestSystemInitializer.getLogDirectory()); 99 } catch (ConfigurationException ex) { 100 ex.printStackTrace(); 101 fail("Unable to set up test case: " + ex.getMessage()); 102 } 103 104 105 } 106 107 110 protected void tearDown() { 111 globalContainer.destroy(); 112 globalContainer = null; 113 System.gc(); 114 System.runFinalization(); 115 } 116 117 120 public void testLocateComponent() { 121 try { 122 LocatorUtils lu = new LocatorUtils((ExpressoComponent) globalContainer); 126 ExpressoComponent test = lu.locateComponent(""); 127 assertTrue("Root component must not be null", test != null); 128 assertTrue("Test should be the same as the global container", test == globalContainer); 129 130 test = lu.locateComponent("default"); 131 assertTrue("Test component must be named default", "default".equals(test.getMetaData().getName())); 132 assertTrue("Test component must be a component container", test instanceof Containable); 133 134 test = lu.locateComponent("default.TestComponent"); 135 assertTrue("Test component must be named TestComponent", 136 "TestComponent".equals(test.getMetaData().getName())); 137 138 lu = new LocatorUtils(test); 143 144 test = lu.locateComponent(""); 145 assertTrue("Root component must not be null", test != null); 146 assertTrue("Test should be the same as the global container", test == globalContainer); 147 148 test = lu.locateComponent("default"); 149 assertTrue("Test component must be named default", "default".equals(test.getMetaData().getName())); 150 assertTrue("Test component must be a component container", test instanceof Containable); 151 152 test = lu.locateComponent("default.TestComponent"); 153 assertTrue("Test component must be named TestComponent", 154 "TestComponent".equals(test.getMetaData().getName())); 155 156 try { 160 test = lu.locateComponent("abcdkefjj"); 161 fail("Should have thrown an exception upon bad input"); 162 } catch (IllegalArgumentException ex) { 163 164 } 165 166 try { 167 test = lu.locateComponent("default..TestComponent"); 168 fail("Should have thrown an exception upon bad input"); 169 } catch (IllegalArgumentException ex) { 170 171 } 172 173 try { 174 test = lu.locateComponent(".default.TestComponent"); 175 fail("Should have thrown an exception upon bad input"); 176 } catch (IllegalArgumentException ex) { 177 178 } 179 180 try { 181 test = lu.locateComponent("default.ancdkiekel/"); 182 fail("Should have thrown an exception upon bad input"); 183 } catch (IllegalArgumentException ex) { 184 185 } 186 } catch (Exception ex) { 187 ex.printStackTrace(); 188 fail("Error locating components " + ex.getMessage()); 189 } 190 191 } 192 193 196 public void testLocateConfiguration() { 197 LocatorUtils lu = new LocatorUtils((ExpressoComponent) globalContainer); 198 ComponentConfig test = lu.locateConfiguration(""); 199 assertTrue("Root component must not be null", test != null); 200 201 test = lu.locateConfiguration("default"); 202 assertTrue("Test component must be named default", "default".equals(test.getName())); 203 204 test = lu.locateConfiguration("default.TestComponent"); 205 assertTrue("Test component must be named TestComponent", 206 "TestComponent".equals(test.getName())); 207 208 try { 212 test = lu.locateConfiguration("abcdkefjj"); 213 fail("Should have thrown an exception upon bad input"); 214 } catch (IllegalArgumentException ex) { 215 216 } 217 218 try { 219 test = lu.locateConfiguration("default..TestComponent"); 220 fail("Should have thrown an exception upon bad input"); 221 } catch (IllegalArgumentException ex) { 222 223 } 224 225 try { 226 test = lu.locateConfiguration(".default.TestComponent"); 227 fail("Should have thrown an exception upon bad input"); 228 } catch (IllegalArgumentException ex) { 229 230 } 231 232 try { 233 test = lu.locateConfiguration("default.ancdkiekel/"); 234 fail("Should have thrown an exception upon bad input"); 235 } catch (IllegalArgumentException ex) { 236 237 } 238 239 } 240 241 244 public void testLocateMetadata() { 245 LocatorUtils lu = new LocatorUtils((ExpressoComponent) globalContainer); 246 ComponentMetadata test = lu.locateMetadata(""); 247 assertTrue("Root component must not be null", test != null); 248 249 test = lu.locateMetadata("default"); 250 assertTrue("Test component must be named default", "default".equals(test.getName())); 251 252 test = lu.locateMetadata("default.TestComponent"); 253 assertTrue("Test component must be named TestComponent", 254 "TestComponent".equals(test.getName())); 255 256 try { 260 test = lu.locateMetadata("abcdkefjj"); 261 fail("Should have thrown an exception upon bad input"); 262 } catch (IllegalArgumentException ex) { 263 264 } 265 266 try { 267 test = lu.locateMetadata("default..TestComponent"); 268 fail("Should have thrown an exception upon bad input"); 269 } catch (IllegalArgumentException ex) { 270 271 } 272 273 try { 274 test = lu.locateMetadata(".default.TestComponent"); 275 fail("Should have thrown an exception upon bad input"); 276 } catch (IllegalArgumentException ex) { 277 278 } 279 280 try { 281 test = lu.locateMetadata("default.ancdkiekel/"); 282 fail("Should have thrown an exception upon bad input"); 283 } catch (IllegalArgumentException ex) { 284 285 } 286 287 288 } 289 290 294 public void testCreatePath() { 295 LocatorUtils lu = new LocatorUtils((ExpressoComponent) globalContainer); 296 ExpressoComponent test = lu.locateComponent(""); 297 assertTrue("Root component must not be null", test != null); 298 assertTrue("".equals(lu.getPath(test))); 299 300 test = lu.locateComponent("default"); 301 assertTrue("default component must not be null", test != null); 302 assertTrue("default".equals(lu.getPath(test))); 303 304 test = lu.locateComponent("default.TestComponent"); 305 assertTrue("default.TestComponent must not be null", test != null); 306 assertTrue("default.TestComponent".equals(lu.getPath(test))); 307 308 } 309 310 313 public static void main(String [] argv) { 314 String [] testCaseList = {TestLocatorUtils.class.getName()}; 315 junit.textui.TestRunner.main(testCaseList); 316 } 317 } 318 | Popular Tags |