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: ImplementationTest.java 4459 2012-03-27 23:55:31Z schulte2005 $ 032 * 033 */ 034 // </editor-fold> 035 // SECTION-END 036 package org.jomc.ri.test; 037 038 import java.util.Locale; 039 import org.junit.Test; 040 import static org.junit.Assert.assertNull; 041 042 // SECTION-START[Documentation] 043 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 044 /** 045 * Implementation {@code <JOMC :: RI :: Tests :: Implementation Test>}. 046 * 047 * <dl> 048 * <dt><b>Identifier:</b></dt><dd>JOMC :: RI :: Tests :: Implementation Test</dd> 049 * <dt><b>Name:</b></dt><dd>JOMC :: RI :: Tests :: Implementation Test</dd> 050 * <dt><b>Specifications:</b></dt> 051 * <dd>JOMC :: RI :: Tests :: Test Multiton Specification @ 1.2.2</dd> 052 * <dd>JOMC :: RI :: Tests :: Test Scope Specification @ 1.2.2</dd> 053 * <dd>JOMC :: RI :: Tests :: Test Singleton Specification @ 1.2.2</dd> 054 * <dd>JOMC :: RI :: Tests :: Test Specification Many @ 1.2.2</dd> 055 * <dd>JOMC :: RI :: Tests :: Test Specification One @ 1.2.2</dd> 056 * <dt><b>Abstract:</b></dt><dd>No</dd> 057 * <dt><b>Final:</b></dt><dd>No</dd> 058 * <dt><b>Stateless:</b></dt><dd>No</dd> 059 * </dl> 060 * 061 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 062 * @version 1.2.2 063 */ 064 // </editor-fold> 065 // SECTION-END 066 // SECTION-START[Annotations] 067 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 068 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 069 // </editor-fold> 070 // SECTION-END 071 public class ImplementationTest 072 implements 073 org.jomc.ri.test.support.TestSpecification, 074 org.jomc.ri.test.support.TestSpecificationOne, 075 org.jomc.ri.test.support.TestSpecificationMany, 076 org.jomc.ri.test.support.TestScopeSpecification 077 { 078 // SECTION-START[TestSpecification] 079 // SECTION-END 080 // SECTION-START[TestScopeSpecification] 081 // SECTION-END 082 // SECTION-START[TestSpecificationMany] 083 // SECTION-END 084 // SECTION-START[TestSpecificationOne] 085 // SECTION-END 086 // SECTION-START[ImplementationTest] 087 088 private static final int NUM_REQUESTS = 25000; 089 090 private static final int NUM_RUNS = 2; 091 092 @Test 093 public final void testBoundMultitons() throws Exception 094 { 095 this.printEstimatedExecutionTime( "BoundMultitons", new Runnable() 096 { 097 098 public void run() 099 { 100 getBoundMultitons(); 101 } 102 103 } ); 104 105 } 106 107 @Test 108 public final void testUnboundMultitons() throws Exception 109 { 110 this.printEstimatedExecutionTime( "UnboundMultitons", new Runnable() 111 { 112 113 public void run() 114 { 115 getUnboundMultitons(); 116 } 117 118 } ); 119 120 } 121 122 @Test 123 public final void testSelectedBoundMultiton() throws Exception 124 { 125 this.printEstimatedExecutionTime( "SelectedBoundMultiton", new Runnable() 126 { 127 128 public void run() 129 { 130 getSelectedBoundMultiton(); 131 } 132 133 } ); 134 135 } 136 137 @Test 138 public final void testSelectedUnboundMultiton() throws Exception 139 { 140 this.printEstimatedExecutionTime( "SelectedUnboundMultiton", new Runnable() 141 { 142 143 public void run() 144 { 145 getSelectedUnboundMultiton(); 146 } 147 148 } ); 149 150 } 151 152 @Test 153 public final void testBoundSingletons() throws Exception 154 { 155 this.printEstimatedExecutionTime( "BoundSingletons", new Runnable() 156 { 157 158 public void run() 159 { 160 getBoundSingletons(); 161 } 162 163 } ); 164 165 } 166 167 @Test 168 public final void testUnboundSingletons() throws Exception 169 { 170 this.printEstimatedExecutionTime( "UnboundSingletons", new Runnable() 171 { 172 173 public void run() 174 { 175 getUnboundSingletons(); 176 } 177 178 } ); 179 180 } 181 182 @Test 183 public final void testSelectedBoundSingleton() throws Exception 184 { 185 this.printEstimatedExecutionTime( "SelectedBoundSingleton", new Runnable() 186 { 187 188 public void run() 189 { 190 getSelectedBoundSingleton(); 191 } 192 193 } ); 194 195 } 196 197 @Test 198 public final void testSelectedUnboundSingleton() throws Exception 199 { 200 this.printEstimatedExecutionTime( "SelectedUnboundSingleton", new Runnable() 201 { 202 203 public void run() 204 { 205 getSelectedUnboundSingleton(); 206 } 207 208 } ); 209 210 } 211 212 @Test 213 public final void testProperties() throws Exception 214 { 215 this.printEstimatedExecutionTime( "TestProperty", new Runnable() 216 { 217 218 public void run() 219 { 220 getTestProperty(); 221 } 222 223 } ); 224 225 } 226 227 @Test 228 public final void testMessages() throws Exception 229 { 230 this.printEstimatedExecutionTime( "TestMessage", new Runnable() 231 { 232 233 public void run() 234 { 235 getTestMessage( Locale.getDefault(), "arg" ); 236 } 237 238 } ); 239 240 } 241 242 @Test 243 public final void testOptionalDependency() throws Exception 244 { 245 assertNull( this.getOptionalLocale() ); 246 } 247 248 @Test 249 public final void testInvoker() throws Exception 250 { 251 this.getInvokerTestSpecification().invoke( "TEST" ); 252 } 253 254 protected void printEstimatedExecutionTime( final String identifier, final Runnable runnable ) 255 { 256 long t = 0L; 257 258 for ( int i = NUM_RUNS - 1; i >= 0; i-- ) 259 { 260 final long t0 = System.currentTimeMillis(); 261 262 for ( long l = NUM_REQUESTS - 1; l >= 0; l-- ) 263 { 264 runnable.run(); 265 } 266 267 t += ( System.currentTimeMillis() - t0 ); 268 } 269 270 System.out.println( NUM_REQUESTS + " * '" + identifier + "': ~" + ( t / NUM_RUNS ) + "ms." ); 271 } 272 273 // SECTION-END 274 // SECTION-START[Constructors] 275 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 276 /** Creates a new {@code ImplementationTest} instance. */ 277 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 278 public ImplementationTest() 279 { 280 // SECTION-START[Default Constructor] 281 super(); 282 // SECTION-END 283 } 284 // </editor-fold> 285 // SECTION-END 286 // SECTION-START[Dependencies] 287 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> 288 /** 289 * Gets the {@code <BoundMultitons>} dependency. 290 * <p> 291 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Multiton Specification>} specification at specification level 1.2.2. 292 * That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance. 293 * </p> 294 * <dl> 295 * <dt><b>Final:</b></dt><dd>No</dd> 296 * </dl> 297 * @return The {@code <BoundMultitons>} dependency. 298 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 299 */ 300 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 301 private org.jomc.ri.test.support.TestSpecification[] getBoundMultitons() 302 { 303 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "BoundMultitons" ); 304 assert _d != null : "'BoundMultitons' dependency not found."; 305 return _d; 306 } 307 /** 308 * Gets the {@code <BoundSingletons>} dependency. 309 * <p> 310 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.2.2. 311 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 312 * </p> 313 * <dl> 314 * <dt><b>Final:</b></dt><dd>No</dd> 315 * </dl> 316 * @return The {@code <BoundSingletons>} dependency. 317 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 318 */ 319 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 320 private org.jomc.ri.test.support.TestSpecification[] getBoundSingletons() 321 { 322 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "BoundSingletons" ); 323 assert _d != null : "'BoundSingletons' dependency not found."; 324 return _d; 325 } 326 /** 327 * Gets the {@code <InvokerTestSpecification>} dependency. 328 * <p> 329 * This method returns the {@code <JOMC :: RI :: Tests :: Invoker Test Implementation>} object of the {@code <JOMC :: RI :: Tests :: Invoker Test Specification>} specification at specification level 1.2.2. 330 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 331 * </p> 332 * <dl> 333 * <dt><b>Final:</b></dt><dd>No</dd> 334 * </dl> 335 * @return The {@code <InvokerTestSpecification>} dependency. 336 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 337 */ 338 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 339 private org.jomc.ri.test.support.InvokerTestSpecification getInvokerTestSpecification() 340 { 341 final org.jomc.ri.test.support.InvokerTestSpecification _d = (org.jomc.ri.test.support.InvokerTestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "InvokerTestSpecification" ); 342 assert _d != null : "'InvokerTestSpecification' dependency not found."; 343 return _d; 344 } 345 /** 346 * Gets the {@code <OptionalLocale>} dependency. 347 * <p> 348 * This method returns the {@code <DOES NOT EXIST>} object of the {@code <java.util.Locale>} specification at specification level 1.1. 349 * That specification does not apply to any scope. A new object is returned whenever requested. 350 * </p> 351 * <dl> 352 * <dt><b>Final:</b></dt><dd>No</dd> 353 * </dl> 354 * @return The {@code <OptionalLocale>} dependency. 355 * {@code null} if no object is available. 356 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 357 */ 358 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 359 private java.util.Locale getOptionalLocale() 360 { 361 return (java.util.Locale) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "OptionalLocale" ); 362 } 363 /** 364 * Gets the {@code <SelectedBoundMultiton>} dependency. 365 * <p> 366 * This method returns the {@code <JOMC :: RI :: Tests :: Implementation Test>} object of the {@code <JOMC :: RI :: Tests :: Test Multiton Specification>} specification at specification level 1.2.2. 367 * That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance. 368 * </p> 369 * <dl> 370 * <dt><b>Final:</b></dt><dd>No</dd> 371 * </dl> 372 * @return The {@code <SelectedBoundMultiton>} dependency. 373 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 374 */ 375 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 376 private org.jomc.ri.test.support.TestSpecification getSelectedBoundMultiton() 377 { 378 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedBoundMultiton" ); 379 assert _d != null : "'SelectedBoundMultiton' dependency not found."; 380 return _d; 381 } 382 /** 383 * Gets the {@code <SelectedBoundSingleton>} dependency. 384 * <p> 385 * This method returns the {@code <JOMC :: RI :: Tests :: Implementation Test>} object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.2.2. 386 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 387 * </p> 388 * <dl> 389 * <dt><b>Final:</b></dt><dd>No</dd> 390 * </dl> 391 * @return The {@code <SelectedBoundSingleton>} dependency. 392 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 393 */ 394 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 395 private org.jomc.ri.test.support.TestSpecification getSelectedBoundSingleton() 396 { 397 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedBoundSingleton" ); 398 assert _d != null : "'SelectedBoundSingleton' dependency not found."; 399 return _d; 400 } 401 /** 402 * Gets the {@code <SelectedUnboundMultiton>} dependency. 403 * <p> 404 * This method returns the {@code <JOMC :: RI :: Tests :: Implementation Test>} object of the {@code <JOMC :: RI :: Tests :: Test Multiton Specification>} specification at specification level 1.2.2. 405 * That specification does not apply to any scope. A new object is returned whenever requested. 406 * </p> 407 * <dl> 408 * <dt><b>Final:</b></dt><dd>No</dd> 409 * </dl> 410 * @return The {@code <SelectedUnboundMultiton>} dependency. 411 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 412 */ 413 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 414 private org.jomc.ri.test.support.TestSpecification getSelectedUnboundMultiton() 415 { 416 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedUnboundMultiton" ); 417 assert _d != null : "'SelectedUnboundMultiton' dependency not found."; 418 return _d; 419 } 420 /** 421 * Gets the {@code <SelectedUnboundSingleton>} dependency. 422 * <p> 423 * This method returns the {@code <JOMC :: RI :: Tests :: Implementation Test>} object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.2.2. 424 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested. 425 * </p> 426 * <dl> 427 * <dt><b>Final:</b></dt><dd>No</dd> 428 * </dl> 429 * @return The {@code <SelectedUnboundSingleton>} dependency. 430 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 431 */ 432 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 433 private org.jomc.ri.test.support.TestSpecification getSelectedUnboundSingleton() 434 { 435 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedUnboundSingleton" ); 436 assert _d != null : "'SelectedUnboundSingleton' dependency not found."; 437 return _d; 438 } 439 /** 440 * Gets the {@code <UnboundMultitons>} dependency. 441 * <p> 442 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Multiton Specification>} specification at specification level 1.2.2. 443 * That specification does not apply to any scope. A new object is returned whenever requested. 444 * </p> 445 * <dl> 446 * <dt><b>Final:</b></dt><dd>No</dd> 447 * </dl> 448 * @return The {@code <UnboundMultitons>} dependency. 449 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 450 */ 451 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 452 private org.jomc.ri.test.support.TestSpecification[] getUnboundMultitons() 453 { 454 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "UnboundMultitons" ); 455 assert _d != null : "'UnboundMultitons' dependency not found."; 456 return _d; 457 } 458 /** 459 * Gets the {@code <UnboundSingletons>} dependency. 460 * <p> 461 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.2.2. 462 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested. 463 * </p> 464 * <dl> 465 * <dt><b>Final:</b></dt><dd>No</dd> 466 * </dl> 467 * @return The {@code <UnboundSingletons>} dependency. 468 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 469 */ 470 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 471 private org.jomc.ri.test.support.TestSpecification[] getUnboundSingletons() 472 { 473 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "UnboundSingletons" ); 474 assert _d != null : "'UnboundSingletons' dependency not found."; 475 return _d; 476 } 477 // </editor-fold> 478 // SECTION-END 479 // SECTION-START[Properties] 480 // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> 481 /** 482 * Gets the value of the {@code <testProperty>} property. 483 * <p><dl> 484 * <dt><b>Final:</b></dt><dd>No</dd> 485 * </dl></p> 486 * @return The value of the {@code <testProperty>} property. 487 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 488 */ 489 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 490 private java.lang.String getTestProperty() 491 { 492 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testProperty" ); 493 assert _p != null : "'testProperty' property not found."; 494 return _p; 495 } 496 // </editor-fold> 497 // SECTION-END 498 // SECTION-START[Messages] 499 // <editor-fold defaultstate="collapsed" desc=" Generated Messages "> 500 /** 501 * Gets the text of the {@code <testMessage>} message. 502 * <p><dl> 503 * <dt><b>Languages:</b></dt> 504 * <dd>English (default)</dd> 505 * <dt><b>Final:</b></dt><dd>No</dd> 506 * </dl></p> 507 * @param locale The locale of the message to return. 508 * @param testArgument Format argument. 509 * @return The text of the {@code <testMessage>} message for {@code locale}. 510 * @throws org.jomc.ObjectManagementException if getting the message instance fails. 511 */ 512 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) 513 private String getTestMessage( final java.util.Locale locale, final java.lang.String testArgument ) 514 { 515 final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "testMessage", locale, testArgument ); 516 assert _m != null : "'testMessage' message not found."; 517 return _m; 518 } 519 // </editor-fold> 520 // SECTION-END 521 }