001// SECTION-START[License Header] 002// <editor-fold defaultstate="collapsed" desc=" Generated License "> 003/* 004 * Java Object Management and Configuration 005 * Copyright (C) Christian Schulte, 2005-206 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions 010 * are met: 011 * 012 * o Redistributions of source code must retain the above copyright 013 * notice, this list of conditions and the following disclaimer. 014 * 015 * o Redistributions in binary form must reproduce the above copyright 016 * notice, this list of conditions and the following disclaimer in 017 * the documentation and/or other materials provided with the 018 * distribution. 019 * 020 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 021 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 022 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 023 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 025 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 029 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 * 031 * $JOMC: DefaultObjectManagerTest.java 4588 2012-06-03 06:01:30Z schulte2005 $ 032 * 033 */ 034// </editor-fold> 035// SECTION-END 036package org.jomc.ri.test; 037 038import java.net.URI; 039import java.util.Locale; 040import org.jomc.ObjectManager; 041import org.jomc.model.Instance; 042import org.jomc.model.Modules; 043import org.jomc.ri.DefaultObjectManager; 044import org.jomc.ri.test.support.TestScopeSpecification; 045import org.jomc.ri.test.support.TestSpecification; 046import org.jomc.ri.test.support.TestSpecificationMany; 047import org.jomc.ri.test.support.TestSpecificationOne; 048import org.jomc.ri.test.support.TestSpecificationOneMore; 049import org.jomc.spi.Scope; 050import org.junit.Test; 051import static org.junit.Assert.assertNotNull; 052import static org.junit.Assert.assertNull; 053import static org.junit.Assert.assertTrue; 054import static org.junit.Assert.fail; 055 056// SECTION-START[Documentation] 057// <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 058/** 059 * Test cases for the {@code DefaultObjectManager} class. 060 * 061 * <dl> 062 * <dt><b>Identifier:</b></dt><dd>JOMC :: RI :: Tests :: Default Object Manager Test</dd> 063 * <dt><b>Name:</b></dt><dd>JOMC RI</dd> 064 * <dt><b>Abstract:</b></dt><dd>No</dd> 065 * <dt><b>Final:</b></dt><dd>No</dd> 066 * <dt><b>Stateless:</b></dt><dd>No</dd> 067 * </dl> 068 * 069 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 070 * @version 1.3 071 */ 072// </editor-fold> 073// SECTION-END 074// SECTION-START[Annotations] 075// <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 076@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 077// </editor-fold> 078// SECTION-END 079public class DefaultObjectManagerTest 080{ 081 // SECTION-START[DefaultObjectManagerTest] 082 083 /** The {@code DefaultObjectManager} tests are performed with. */ 084 private DefaultObjectManager objectManager; 085 086 /** 087 * Gets the instance tests are performed with. 088 * 089 * @return The instance tests are performed with. 090 * 091 * @see #newObjectManager() 092 */ 093 public DefaultObjectManager getObjectManager() 094 { 095 if ( this.objectManager == null ) 096 { 097 this.objectManager = this.newObjectManager(); 098 } 099 100 return this.objectManager; 101 } 102 103 /** 104 * Creates a new {@code DefaultObjectManager} instance to test. 105 * 106 * @return A new {@code DefaultObjectManager} instance to test. 107 * 108 * @see #getObjectManager() 109 */ 110 protected DefaultObjectManager newObjectManager() 111 { 112 return new DefaultObjectManager(); 113 } 114 115 @Test 116 @SuppressWarnings( "deprecation" ) 117 public final void testNullPointerException() throws Exception 118 { 119 try 120 { 121 DefaultObjectManager.getClassLoader( (Class) null ); 122 fail( "Expected NullPointerException not thrown." ); 123 } 124 catch ( final NullPointerException e ) 125 { 126 assertNullPointerException( e ); 127 } 128 129 try 130 { 131 this.getObjectManager().getDefaultClassLoader( (Class<?>) null ); 132 fail( "Expected NullPointerException not thrown." ); 133 } 134 catch ( final NullPointerException e ) 135 { 136 assertNullPointerException( e ); 137 } 138 139 try 140 { 141 this.getObjectManager().getDefaultLocator( null ); 142 fail( "Expected NullPointerException not thrown." ); 143 } 144 catch ( final NullPointerException e ) 145 { 146 assertNullPointerException( e ); 147 } 148 try 149 { 150 this.getObjectManager().getDefaultLocator( null, new URI( "file:///tmp" ) ); 151 fail( "Expected NullPointerException not thrown." ); 152 } 153 catch ( final NullPointerException e ) 154 { 155 assertNullPointerException( e ); 156 } 157 158 try 159 { 160 this.getObjectManager().getDefaultScope( null ); 161 fail( "Expected NullPointerException not thrown." ); 162 } 163 catch ( final NullPointerException e ) 164 { 165 assertNullPointerException( e ); 166 } 167 try 168 { 169 this.getObjectManager().getDefaultScope( new Modules(), null ); 170 fail( "Expected NullPointerException not thrown." ); 171 } 172 catch ( final NullPointerException e ) 173 { 174 assertNullPointerException( e ); 175 } 176 try 177 { 178 this.getObjectManager().getDefaultScope( null, "Singleton" ); 179 fail( "Expected NullPointerException not thrown." ); 180 } 181 catch ( final NullPointerException e ) 182 { 183 assertNullPointerException( e ); 184 } 185 186 try 187 { 188 this.getObjectManager().getDependency( null, null ); 189 fail( "Expected NullPointerException not thrown." ); 190 } 191 catch ( final NullPointerException e ) 192 { 193 assertNullPointerException( e ); 194 } 195 196 try 197 { 198 this.getObjectManager().getDependency( this, null ); 199 fail( "Expected NullPointerException not thrown." ); 200 } 201 catch ( final NullPointerException e ) 202 { 203 assertNullPointerException( e ); 204 } 205 206 try 207 { 208 this.getObjectManager().getLocator( null, null ); 209 fail( "Expected NullPointerException not thrown." ); 210 } 211 catch ( final NullPointerException e ) 212 { 213 assertNullPointerException( e ); 214 } 215 216 try 217 { 218 this.getObjectManager().getLocator( new URI( "TEST" ), null ); 219 fail( "Expected NullPointerException not thrown." ); 220 } 221 catch ( final NullPointerException e ) 222 { 223 assertNullPointerException( e ); 224 } 225 226 try 227 { 228 this.getObjectManager().getLocator( null, this.getClass().getClassLoader() ); 229 fail( "Expected NullPointerException not thrown." ); 230 } 231 catch ( final NullPointerException e ) 232 { 233 assertNullPointerException( e ); 234 } 235 236 try 237 { 238 this.getObjectManager().getMessage( null, null, null ); 239 fail( "Expected NullPointerException not thrown." ); 240 } 241 catch ( final NullPointerException e ) 242 { 243 assertNullPointerException( e ); 244 } 245 246 try 247 { 248 this.getObjectManager().getMessage( this, null, null ); 249 fail( "Expected NullPointerException not thrown." ); 250 } 251 catch ( final NullPointerException e ) 252 { 253 assertNullPointerException( e ); 254 } 255 256 try 257 { 258 this.getObjectManager().getMessage( this, "", null ); 259 fail( "Expected NullPointerException not thrown." ); 260 } 261 catch ( final NullPointerException e ) 262 { 263 assertNullPointerException( e ); 264 } 265 266 try 267 { 268 this.getObjectManager().getObject( null ); 269 fail( "Expected NullPointerException not thrown." ); 270 } 271 catch ( final NullPointerException e ) 272 { 273 assertNullPointerException( e ); 274 } 275 276 try 277 { 278 this.getObjectManager().getObject( (Scope) null, (Instance) null, null ); 279 fail( "Expected NullPointerException not thrown." ); 280 } 281 catch ( final NullPointerException e ) 282 { 283 assertNullPointerException( e ); 284 } 285 286 try 287 { 288 this.getObjectManager().getObject( (Scope) null, new Instance(), null ); 289 fail( "Expected NullPointerException not thrown." ); 290 } 291 catch ( final NullPointerException e ) 292 { 293 assertNullPointerException( e ); 294 } 295 296 try 297 { 298 this.getObjectManager().getObject( (Class<?>) null, null, null ); 299 fail( "Expected NullPointerException not thrown." ); 300 } 301 catch ( final NullPointerException e ) 302 { 303 assertNullPointerException( e ); 304 } 305 306 try 307 { 308 this.getObjectManager().getObject( this.getClass(), null, null ); 309 fail( "Expected NullPointerException not thrown." ); 310 } 311 catch ( final NullPointerException e ) 312 { 313 assertNullPointerException( e ); 314 } 315 316 try 317 { 318 this.getObjectManager().getObject( this.getClass(), new URI( "/" ), null ); 319 fail( "Expected NullPointerException not thrown." ); 320 } 321 catch ( final NullPointerException e ) 322 { 323 assertNullPointerException( e ); 324 } 325 326 try 327 { 328 this.getObjectManager().getProperty( null, null ); 329 fail( "Expected NullPointerException not thrown." ); 330 } 331 catch ( final NullPointerException e ) 332 { 333 assertNullPointerException( e ); 334 } 335 336 try 337 { 338 this.getObjectManager().getProperty( this, null ); 339 fail( "Expected NullPointerException not thrown." ); 340 } 341 catch ( final NullPointerException e ) 342 { 343 assertNullPointerException( e ); 344 } 345 346 try 347 { 348 this.getObjectManager().getScope( null, null ); 349 fail( "Expected NullPointerException not thrown." ); 350 } 351 catch ( final NullPointerException e ) 352 { 353 assertNullPointerException( e ); 354 } 355 356 try 357 { 358 this.getObjectManager().getScope( "TEST", null ); 359 fail( "Expected NullPointerException not thrown." ); 360 } 361 catch ( final NullPointerException e ) 362 { 363 assertNullPointerException( e ); 364 } 365 366 try 367 { 368 this.getObjectManager().getScope( null, this.getClass().getClassLoader() ); 369 fail( "Expected NullPointerException not thrown." ); 370 } 371 catch ( final NullPointerException e ) 372 { 373 assertNullPointerException( e ); 374 } 375 376 try 377 { 378 this.getObjectManager().log( null, null, null ); 379 fail( "Expected NullPointerException not thrown." ); 380 } 381 catch ( final NullPointerException e ) 382 { 383 assertNullPointerException( e ); 384 } 385 386 try 387 { 388 this.getObjectManager().log( null, null, null, null ); 389 fail( "Expected NullPointerException not thrown." ); 390 } 391 catch ( final NullPointerException e ) 392 { 393 assertNullPointerException( e ); 394 } 395 396 try 397 { 398 this.getObjectManager().log( this.getClass().getClassLoader(), null, null, null ); 399 fail( "Expected NullPointerException not thrown." ); 400 } 401 catch ( final NullPointerException e ) 402 { 403 assertNullPointerException( e ); 404 } 405 } 406 407 @Test 408 public final void testNotNull() throws Exception 409 { 410 assertNotNull( this.getObjectManager().getListeners() ); 411 assertNotNull( this.getObjectManager().getModules( this.getClass().getClassLoader() ) ); 412 assertNotNull( this.getObjectManager().getObject( TestSpecificationOne.class ) ); 413 assertNotNull( this.getObjectManager().getObject( TestSpecificationOne.class, 414 "JOMC :: RI :: Tests :: Implementation Test" ) ); 415 416 assertNotNull( this.getObjectManager().getObject( TestSpecificationMany[].class ) ); 417 assertNotNull( this.getObjectManager().getObject( TestSpecificationMany.class, 418 "JOMC :: RI :: Tests :: Implementation Test" ) ); 419 420 assertNotNull( this.getObjectManager().getObject( TestScopeSpecification[].class ) ); 421 assertNotNull( this.getObjectManager().getObject( TestScopeSpecification.class, 422 "JOMC :: RI :: Tests :: Implementation Test" ) ); 423 424 } 425 426 @Test 427 public final void testNull() throws Exception 428 { 429 assertNull( this.getObjectManager().getObject( Object.class ) ); 430 assertNull( this.getObjectManager().getObject( TestSpecification.class ) ); 431 assertNull( this.getObjectManager().getObject( TestSpecificationOne[].class ) ); 432 assertNull( this.getObjectManager().getObject( TestSpecificationOneMore.class ) ); 433 assertNull( this.getObjectManager().getObject( TestSpecificationMany.class ) ); 434 assertNull( this.getObjectManager().getObject( ObjectManager.class, "DOES NOT EXIST" ) ); 435 assertNull( this.getObjectManager().getObject( TestSpecification.class, "DOES NOT EXIST" ) ); 436 assertNull( this.getObjectManager().getDependency( this, "DOES NOT EXIST" ) ); 437 assertNull( this.getObjectManager().getProperty( this, "DOES NOT EXIST" ) ); 438 assertNull( this.getObjectManager().getMessage( this, "DOES NOT EXIST", Locale.getDefault() ) ); 439 assertNull( this.getObjectManager().getObject( TestSpecificationOneMore.class, 440 "JOMC :: RI :: Tests :: Illegal Location Implementation" ) ); 441 442 assertNull( this.getObjectManager().getObject( TestScopeSpecification.class, 443 "JOMC :: RI :: Tests :: Illegal Location Implementation" ) ); 444 445 } 446 447 @Test 448 public final void testGetObjectManager() throws Exception 449 { 450 final ObjectManager first = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() ); 451 final ObjectManager second = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() ); 452 final ObjectManager third = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() ); 453 454 assertTrue( first == second ); 455 assertTrue( first == third ); 456 assertTrue( second == third ); 457 } 458 459 public static void assertNullPointerException( final NullPointerException e ) 460 { 461 assertNotNull( e.getMessage() ); 462 System.out.println( e.toString() ); 463 } 464 465 // SECTION-END 466 // SECTION-START[Constructors] 467 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 468 /** Creates a new {@code DefaultObjectManagerTest} instance. */ 469 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 470 public DefaultObjectManagerTest() 471 { 472 // SECTION-START[Default Constructor] 473 super(); 474 // SECTION-END 475 } 476 // </editor-fold> 477 // SECTION-END 478 // SECTION-START[Dependencies] 479 // SECTION-END 480 // SECTION-START[Properties] 481 // SECTION-END 482 // SECTION-START[Messages] 483 // SECTION-END 484}