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 4588 2012-06-03 06:01:30Z schulte2005 $ 032 * 033 */ 034// </editor-fold> 035// SECTION-END 036package org.jomc.ri.test; 037 038import java.util.Locale; 039import org.junit.Test; 040import 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.3</dd> 052 * <dd>JOMC :: RI :: Tests :: Test Scope Specification @ 1.3</dd> 053 * <dd>JOMC :: RI :: Tests :: Test Singleton Specification @ 1.3</dd> 054 * <dd>JOMC :: RI :: Tests :: Test Specification Many @ 1.3</dd> 055 * <dd>JOMC :: RI :: Tests :: Test Specification One @ 1.3</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.3 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.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 069// </editor-fold> 070// SECTION-END 071public 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.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 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.3. 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 @SuppressWarnings("unused") 301 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 302 private org.jomc.ri.test.support.TestSpecification[] getBoundMultitons() 303 { 304 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "BoundMultitons" ); 305 assert _d != null : "'BoundMultitons' dependency not found."; 306 return _d; 307 } 308 /** 309 * Gets the {@code <BoundSingletons>} dependency. 310 * <p> 311 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.3. 312 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 313 * </p> 314 * <dl> 315 * <dt><b>Final:</b></dt><dd>No</dd> 316 * </dl> 317 * @return The {@code <BoundSingletons>} dependency. 318 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 319 */ 320 @SuppressWarnings("unused") 321 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 322 private org.jomc.ri.test.support.TestSpecification[] getBoundSingletons() 323 { 324 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "BoundSingletons" ); 325 assert _d != null : "'BoundSingletons' dependency not found."; 326 return _d; 327 } 328 /** 329 * Gets the {@code <InvokerTestSpecification>} dependency. 330 * <p> 331 * 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.3. 332 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 333 * </p> 334 * <dl> 335 * <dt><b>Final:</b></dt><dd>No</dd> 336 * </dl> 337 * @return The {@code <InvokerTestSpecification>} dependency. 338 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 339 */ 340 @SuppressWarnings("unused") 341 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 342 private org.jomc.ri.test.support.InvokerTestSpecification getInvokerTestSpecification() 343 { 344 final org.jomc.ri.test.support.InvokerTestSpecification _d = (org.jomc.ri.test.support.InvokerTestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "InvokerTestSpecification" ); 345 assert _d != null : "'InvokerTestSpecification' dependency not found."; 346 return _d; 347 } 348 /** 349 * Gets the {@code <OptionalLocale>} dependency. 350 * <p> 351 * This method returns the {@code <DOES NOT EXIST>} object of the {@code <java.util.Locale>} specification at specification level 1.1. 352 * That specification does not apply to any scope. A new object is returned whenever requested. 353 * </p> 354 * <dl> 355 * <dt><b>Final:</b></dt><dd>No</dd> 356 * </dl> 357 * @return The {@code <OptionalLocale>} dependency. 358 * {@code null} if no object is available. 359 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 360 */ 361 @SuppressWarnings("unused") 362 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 363 private java.util.Locale getOptionalLocale() 364 { 365 return (java.util.Locale) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "OptionalLocale" ); 366 } 367 /** 368 * Gets the {@code <SelectedBoundMultiton>} dependency. 369 * <p> 370 * 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.3. 371 * That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance. 372 * </p> 373 * <dl> 374 * <dt><b>Final:</b></dt><dd>No</dd> 375 * </dl> 376 * @return The {@code <SelectedBoundMultiton>} dependency. 377 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 378 */ 379 @SuppressWarnings("unused") 380 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 381 private org.jomc.ri.test.support.TestSpecification getSelectedBoundMultiton() 382 { 383 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedBoundMultiton" ); 384 assert _d != null : "'SelectedBoundMultiton' dependency not found."; 385 return _d; 386 } 387 /** 388 * Gets the {@code <SelectedBoundSingleton>} dependency. 389 * <p> 390 * 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.3. 391 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested and bound to this instance. 392 * </p> 393 * <dl> 394 * <dt><b>Final:</b></dt><dd>No</dd> 395 * </dl> 396 * @return The {@code <SelectedBoundSingleton>} dependency. 397 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 398 */ 399 @SuppressWarnings("unused") 400 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 401 private org.jomc.ri.test.support.TestSpecification getSelectedBoundSingleton() 402 { 403 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedBoundSingleton" ); 404 assert _d != null : "'SelectedBoundSingleton' dependency not found."; 405 return _d; 406 } 407 /** 408 * Gets the {@code <SelectedUnboundMultiton>} dependency. 409 * <p> 410 * 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.3. 411 * That specification does not apply to any scope. A new object is returned whenever requested. 412 * </p> 413 * <dl> 414 * <dt><b>Final:</b></dt><dd>No</dd> 415 * </dl> 416 * @return The {@code <SelectedUnboundMultiton>} dependency. 417 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 418 */ 419 @SuppressWarnings("unused") 420 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 421 private org.jomc.ri.test.support.TestSpecification getSelectedUnboundMultiton() 422 { 423 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedUnboundMultiton" ); 424 assert _d != null : "'SelectedUnboundMultiton' dependency not found."; 425 return _d; 426 } 427 /** 428 * Gets the {@code <SelectedUnboundSingleton>} dependency. 429 * <p> 430 * 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.3. 431 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested. 432 * </p> 433 * <dl> 434 * <dt><b>Final:</b></dt><dd>No</dd> 435 * </dl> 436 * @return The {@code <SelectedUnboundSingleton>} dependency. 437 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 438 */ 439 @SuppressWarnings("unused") 440 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 441 private org.jomc.ri.test.support.TestSpecification getSelectedUnboundSingleton() 442 { 443 final org.jomc.ri.test.support.TestSpecification _d = (org.jomc.ri.test.support.TestSpecification) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectedUnboundSingleton" ); 444 assert _d != null : "'SelectedUnboundSingleton' dependency not found."; 445 return _d; 446 } 447 /** 448 * Gets the {@code <UnboundMultitons>} dependency. 449 * <p> 450 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Multiton Specification>} specification at specification level 1.3. 451 * That specification does not apply to any scope. A new object is returned whenever requested. 452 * </p> 453 * <dl> 454 * <dt><b>Final:</b></dt><dd>No</dd> 455 * </dl> 456 * @return The {@code <UnboundMultitons>} dependency. 457 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 458 */ 459 @SuppressWarnings("unused") 460 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 461 private org.jomc.ri.test.support.TestSpecification[] getUnboundMultitons() 462 { 463 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "UnboundMultitons" ); 464 assert _d != null : "'UnboundMultitons' dependency not found."; 465 return _d; 466 } 467 /** 468 * Gets the {@code <UnboundSingletons>} dependency. 469 * <p> 470 * This method returns any available object of the {@code <JOMC :: RI :: Tests :: Test Singleton Specification>} specification at specification level 1.3. 471 * That specification applies to {@code <Singleton>} scope. The singleton object is returned whenever requested. 472 * </p> 473 * <dl> 474 * <dt><b>Final:</b></dt><dd>No</dd> 475 * </dl> 476 * @return The {@code <UnboundSingletons>} dependency. 477 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 478 */ 479 @SuppressWarnings("unused") 480 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 481 private org.jomc.ri.test.support.TestSpecification[] getUnboundSingletons() 482 { 483 final org.jomc.ri.test.support.TestSpecification[] _d = (org.jomc.ri.test.support.TestSpecification[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "UnboundSingletons" ); 484 assert _d != null : "'UnboundSingletons' dependency not found."; 485 return _d; 486 } 487 // </editor-fold> 488 // SECTION-END 489 // SECTION-START[Properties] 490 // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> 491 /** 492 * Gets the value of the {@code <testProperty>} property. 493 * <p><dl> 494 * <dt><b>Final:</b></dt><dd>No</dd> 495 * </dl></p> 496 * @return The value of the {@code <testProperty>} property. 497 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 498 */ 499 @SuppressWarnings("unused") 500 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 501 private java.lang.String getTestProperty() 502 { 503 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testProperty" ); 504 assert _p != null : "'testProperty' property not found."; 505 return _p; 506 } 507 // </editor-fold> 508 // SECTION-END 509 // SECTION-START[Messages] 510 // <editor-fold defaultstate="collapsed" desc=" Generated Messages "> 511 /** 512 * Gets the text of the {@code <testMessage>} message. 513 * <p><dl> 514 * <dt><b>Languages:</b></dt> 515 * <dd>English (default)</dd> 516 * <dt><b>Final:</b></dt><dd>No</dd> 517 * </dl></p> 518 * @param locale The locale of the message to return. 519 * @param testArgument Format argument. 520 * @return The text of the {@code <testMessage>} message for {@code locale}. 521 * @throws org.jomc.ObjectManagementException if getting the message instance fails. 522 */ 523 @SuppressWarnings("unused") 524 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 525 private String getTestMessage( final java.util.Locale locale, final java.lang.String testArgument ) 526 { 527 final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "testMessage", locale, testArgument ); 528 assert _m != null : "'testMessage' message not found."; 529 return _m; 530 } 531 // </editor-fold> 532 // SECTION-END 533}