Java Doc for AbstractTransactionalSpringContextTests.java in  » J2EE » spring-framework-2.0.6 » org » springframework » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.test 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.springframework.test.ConditionalTestCase
   org.springframework.test.AbstractSpringContextTests
      org.springframework.test.AbstractSingleSpringContextTests
         org.springframework.test.AbstractDependencyInjectionSpringContextTests
            org.springframework.test.AbstractTransactionalSpringContextTests

All known Subclasses:   org.springframework.test.AbstractTransactionalDataSourceSpringContextTests,
AbstractTransactionalSpringContextTests
abstract public class AbstractTransactionalSpringContextTests extends AbstractDependencyInjectionSpringContextTests (Code)
Convenient base class for tests that should occur in a transaction, but normally will roll the transaction back on the completion of each test.

This is useful in a range of circumstances, allowing the following benefits:

  • Ability to delete or insert any data in the database, without affecting other tests
  • Providing a transactional context for any code requiring a transaction
  • Ability to write anything to the database without any need to clean up.

This class is typically very fast, compared to traditional setup/teardown scripts.

If data should be left in the database, call the AbstractTransactionalSpringContextTests.setComplete() method in each test. The AbstractTransactionalSpringContextTests.setDefaultRollback "defaultRollback" property, which defaults to "true", determines whether transactions will complete by default.

It is even possible to end the transaction early; for example, to verify lazy loading behavior of an O/R mapping tool. (This is a valuable away to avoid unexpected errors when testing a web UI, for example.) Simply call the AbstractTransactionalSpringContextTests.endTransaction() method. Execution will then occur without a transactional context.

The AbstractTransactionalSpringContextTests.startNewTransaction() method may be called after a call to AbstractTransactionalSpringContextTests.endTransaction() if you wish to create a new transaction, quite independent of the old transaction. The new transaction's default fate will be to roll back, unless AbstractTransactionalSpringContextTests.setComplete() is called again during the scope of the new transaction. Any number of transactions may be created and ended in this way. The final transaction will automatically be rolled back when the test case is torn down.

Transactional behavior requires a single bean in the context implementing the org.springframework.transaction.PlatformTransactionManager interface. This will be set by the superclass's Dependency Injection mechanism. If using the superclass's Field Injection mechanism, the implementation should be named "transactionManager". This mechanism allows the use of the AbstractDependencyInjectionSpringContextTests superclass even when there is more than one transaction manager in the context.

This base class can also be used without transaction management, if no PlatformTransactionManager bean is found in the context provided. Be careful about using this mode, as it allows the potential to permanently modify data. This mode is available only if dependency checking is turned off in the AbstractDependencyInjectionSpringContextTests superclass. The non-transactional capability is provided to enable use of the same subclass in different environments.
author:
   Rod Johnson
author:
   Juergen Hoeller
since:
   1.1.1



Field Summary
protected  TransactionDefinitiontransactionDefinition
     Transaction definition used by this test class: by default, a plain DefaultTransactionDefinition.
protected  PlatformTransactionManagertransactionManager
    
protected  TransactionStatustransactionStatus
     TransactionStatus for this test.

Constructor Summary
public  AbstractTransactionalSpringContextTests()
     Default constructor for AbstractTransactionalSpringContextTests.
public  AbstractTransactionalSpringContextTests(String name)
     Constructor for AbstractTransactionalSpringContextTests with a JUnit name.

Method Summary
protected  voidendTransaction()
     Immediately force a commit or rollback of the transaction, according to the complete flag.
protected  voidonSetUp()
     This implementation creates a transaction before test execution.

Override AbstractTransactionalSpringContextTests.onSetUpBeforeTransaction() and/or AbstractTransactionalSpringContextTests.onSetUpInTransaction() to add custom set-up behavior for transactional execution.

protected  voidonSetUpBeforeTransaction()
     Subclasses can override this method to perform any setup operations, such as populating a database table, before the transaction created by this class.
protected  voidonSetUpInTransaction()
     Subclasses can override this method to perform any setup operations, such as populating a database table, within the transaction created by this class.
protected  voidonTearDown()
     This implementation ends the transaction after test execution.

Override AbstractTransactionalSpringContextTests.onTearDownInTransaction() and/or AbstractTransactionalSpringContextTests.onTearDownAfterTransaction() to add custom tear-down behavior for transactional execution.

protected  voidonTearDownAfterTransaction()
     Subclasses can override this method to perform cleanup after a transaction here.
protected  voidonTearDownInTransaction()
     Subclasses can override this method to run invariant tests here. The transaction is still active at this point, so any changes made in the transaction will still be visible.
protected  voidpreventTransaction()
     Call this method in an overridden AbstractTransactionalSpringContextTests.runBare() method to prevent transactional execution.
protected  voidsetComplete()
     Cause the transaction to commit for this test method, even if default is set to rollback.
public  voidsetDefaultRollback(boolean defaultRollback)
     Subclasses can set this value in their constructor to change default, which is always to roll the transaction back.
protected  voidsetTransactionDefinition(TransactionDefinition customDefinition)
     Call this method in an overridden AbstractTransactionalSpringContextTests.runBare() method to override the transaction attributes that will be used, so that AbstractTransactionalSpringContextTests.setUp() and AbstractTransactionalSpringContextTests.tearDown() behavior is modified.
public  voidsetTransactionManager(PlatformTransactionManager transactionManager)
     Specify the transaction manager to use.
protected  voidstartNewTransaction()
     Start a new transaction.

Field Detail
transactionDefinition
protected TransactionDefinition transactionDefinition(Code)
Transaction definition used by this test class: by default, a plain DefaultTransactionDefinition. Subclasses can change this to cause different behavior.



transactionManager
protected PlatformTransactionManager transactionManager(Code)
The transaction manager to use



transactionStatus
protected TransactionStatus transactionStatus(Code)
TransactionStatus for this test. Typical subclasses won't need to use it.




Constructor Detail
AbstractTransactionalSpringContextTests
public AbstractTransactionalSpringContextTests()(Code)
Default constructor for AbstractTransactionalSpringContextTests.



AbstractTransactionalSpringContextTests
public AbstractTransactionalSpringContextTests(String name)(Code)
Constructor for AbstractTransactionalSpringContextTests with a JUnit name.




Method Detail
endTransaction
protected void endTransaction()(Code)
Immediately force a commit or rollback of the transaction, according to the complete flag.

Can be used to explicitly let the transaction end early, for example to check whether lazy associations of persistent objects work outside of a transaction (that is, have been initialized properly).
See Also:   AbstractTransactionalSpringContextTests.setComplete()




onSetUp
protected void onSetUp() throws Exception(Code)
This implementation creates a transaction before test execution.

Override AbstractTransactionalSpringContextTests.onSetUpBeforeTransaction() and/or AbstractTransactionalSpringContextTests.onSetUpInTransaction() to add custom set-up behavior for transactional execution. Alternatively, override this method for general set-up behavior, calling super.onSetUp() as part of your method implementation.
throws:
  Exception - simply let any exception propagate
See Also:   AbstractTransactionalSpringContextTests.onTearDown()




onSetUpBeforeTransaction
protected void onSetUpBeforeTransaction() throws Exception(Code)
Subclasses can override this method to perform any setup operations, such as populating a database table, before the transaction created by this class. Only invoked if there is a transaction: that is, if AbstractTransactionalSpringContextTests.preventTransaction() has not been invoked in an overridden AbstractTransactionalSpringContextTests.runTest() method.
throws:
  Exception - simply let any exception propagate



onSetUpInTransaction
protected void onSetUpInTransaction() throws Exception(Code)
Subclasses can override this method to perform any setup operations, such as populating a database table, within the transaction created by this class.

NB: Not called if there is no transaction management, due to no transaction manager being provided in the context.

If any Throwable is thrown, the transaction that has been started prior to the execution of this method will be AbstractTransactionalSpringContextTests.endTransaction() ended (or rather an attempt will be made to AbstractTransactionalSpringContextTests.endTransaction() end it gracefully ); The offending Throwable will then be rethrown.
throws:
  Exception - simply let any exception propagate




onTearDown
protected void onTearDown() throws Exception(Code)
This implementation ends the transaction after test execution.

Override AbstractTransactionalSpringContextTests.onTearDownInTransaction() and/or AbstractTransactionalSpringContextTests.onTearDownAfterTransaction() to add custom tear-down behavior for transactional execution. Alternatively, override this method for general tear-down behavior, calling super.onTearDown() as part of your method implementation.

Note that AbstractTransactionalSpringContextTests.onTearDownInTransaction() will only be called if a transaction is still active at the time of the test shutdown. In particular, it will not be called if the transaction has been completed with an explicit AbstractTransactionalSpringContextTests.endTransaction() call before.
throws:
  Exception - simply let any exception propagate
See Also:   AbstractTransactionalSpringContextTests.onSetUp()




onTearDownAfterTransaction
protected void onTearDownAfterTransaction() throws Exception(Code)
Subclasses can override this method to perform cleanup after a transaction here. At this point, the transaction is not active anymore.
throws:
  Exception - simply let any exception propagate



onTearDownInTransaction
protected void onTearDownInTransaction() throws Exception(Code)
Subclasses can override this method to run invariant tests here. The transaction is still active at this point, so any changes made in the transaction will still be visible. However, there is no need to clean up the database, as a rollback will follow automatically.

NB: Not called if there is no actual transaction, for example due to no transaction manager being provided in the application context.
throws:
  Exception - simply let any exception propagate




preventTransaction
protected void preventTransaction()(Code)
Call this method in an overridden AbstractTransactionalSpringContextTests.runBare() method to prevent transactional execution.



setComplete
protected void setComplete()(Code)
Cause the transaction to commit for this test method, even if default is set to rollback.
throws:
  IllegalStateException - if the operation cannot be set tocomplete as no transaction manager was provided



setDefaultRollback
public void setDefaultRollback(boolean defaultRollback)(Code)
Subclasses can set this value in their constructor to change default, which is always to roll the transaction back.



setTransactionDefinition
protected void setTransactionDefinition(TransactionDefinition customDefinition)(Code)
Call this method in an overridden AbstractTransactionalSpringContextTests.runBare() method to override the transaction attributes that will be used, so that AbstractTransactionalSpringContextTests.setUp() and AbstractTransactionalSpringContextTests.tearDown() behavior is modified.
Parameters:
  customDefinition - the custom transaction definition



setTransactionManager
public void setTransactionManager(PlatformTransactionManager transactionManager)(Code)
Specify the transaction manager to use. No transaction management will be available if this is not set. Populated through dependency injection by the superclass.

This mode works only if dependency checking is turned off in the AbstractDependencyInjectionSpringContextTests superclass.




startNewTransaction
protected void startNewTransaction() throws TransactionException(Code)
Start a new transaction. Only call this method if AbstractTransactionalSpringContextTests.endTransaction() has been called. AbstractTransactionalSpringContextTests.setComplete() can be used again in the new transaction. The fate of the new transaction, by default, will be the usual rollback.
throws:
  TransactionException - if starting the transaction failed



Fields inherited from org.springframework.test.AbstractDependencyInjectionSpringContextTests
final public static int AUTOWIRE_BY_NAME(Code)(Java Doc)
final public static int AUTOWIRE_BY_TYPE(Code)(Java Doc)
final public static int AUTOWIRE_NO(Code)(Java Doc)

Methods inherited from org.springframework.test.AbstractDependencyInjectionSpringContextTests
final public int getAutowireMode()(Code)(Java Doc)
protected void injectDependencies() throws Exception(Code)(Java Doc)
final public boolean isDependencyCheck()(Code)(Java Doc)
final public boolean isPopulateProtectedVariables()(Code)(Java Doc)
protected void prepareTestInstance() throws Exception(Code)(Java Doc)
final public void setAutowireMode(int autowireMode)(Code)(Java Doc)
final public void setDependencyCheck(boolean dependencyCheck)(Code)(Java Doc)
final public void setPopulateProtectedVariables(boolean populateFields)(Code)(Java Doc)

Fields inherited from org.springframework.test.AbstractSingleSpringContextTests
protected ConfigurableApplicationContext applicationContext(Code)(Java Doc)

Methods inherited from org.springframework.test.AbstractSingleSpringContextTests
protected Object contextKey()(Code)(Java Doc)
protected ConfigurableApplicationContext createApplicationContext(String[] locations)(Code)(Java Doc)
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory)(Code)(Java Doc)
final public ConfigurableApplicationContext getApplicationContext()(Code)(Java Doc)
protected String[] getConfigLocations()(Code)(Java Doc)
protected String getConfigPath()(Code)(Java Doc)
protected String[] getConfigPaths()(Code)(Java Doc)
final public int getLoadCount()(Code)(Java Doc)
protected ConfigurableApplicationContext loadContext(Object key) throws Exception(Code)(Java Doc)
protected ConfigurableApplicationContext loadContextLocations(String[] locations) throws Exception(Code)(Java Doc)
protected void onSetUp() throws Exception(Code)(Java Doc)
protected void onTearDown() throws Exception(Code)(Java Doc)
protected void prepareTestInstance() throws Exception(Code)(Java Doc)
protected void setDirty()(Code)(Java Doc)
final protected void setUp() throws Exception(Code)(Java Doc)
final protected void tearDown() throws Exception(Code)(Java Doc)

Methods inherited from org.springframework.test.AbstractSpringContextTests
final public void addContext(Object key, ConfigurableApplicationContext context)(Code)(Java Doc)
protected String contextKeyString(Object contextKey)(Code)(Java Doc)
final protected ConfigurableApplicationContext getContext(Object key) throws Exception(Code)(Java Doc)
final protected boolean hasCachedContext(Object contextKey)(Code)(Java Doc)
abstract protected ConfigurableApplicationContext loadContext(Object key) throws Exception(Code)(Java Doc)
final protected void setDirty(Object contextKey)(Code)(Java Doc)

Fields inherited from org.springframework.test.ConditionalTestCase
final protected Log logger(Code)(Java Doc)

Methods inherited from org.springframework.test.ConditionalTestCase
public static int getDisabledTestCount()(Code)(Java Doc)
protected boolean isDisabledInThisEnvironment(String testMethodName)(Code)(Java Doc)
protected int recordDisabled()(Code)(Java Doc)
public void runBare() throws Throwable(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.