Package org.springframework.transaction

Examples of org.springframework.transaction.CallCountingTransactionManager


  private TransactionInterceptor ti;


  public void setUp() {
    this.ptm = new CallCountingTransactionManager();
    this.source = new AnnotationTransactionAttributeSource();
    this.ti = new TransactionInterceptor(this.ptm, this.source);
  }
View Full Code Here


    assertTrue("Stereotype annotation not visible", services.containsKey("testBean"));
  }

  public void testInvokeTransactional() throws Exception {
    TransactionalTestBean testBean = getTestBean();
    CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");

    // try with transactional
    assertEquals("Should not have any started transactions", 0, ptm.begun);
    testBean.findAllFoos();
    assertEquals("Should have 1 started transaction", 1, ptm.begun);
View Full Code Here

    }
  }
 
  public void testNonPublicMethodsNotAdvised() {
    TransactionalTestBean testBean = getTestBean();
    CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");

    assertEquals("Should not have any started transactions", 0, ptm.begun);
    testBean.annotationsOnProtectedAreIgnored();
    assertEquals("Should not have any started transactions", 0, ptm.begun);   
  }
View Full Code Here

*/
public class AnnotationTransactionAttributeSourceTests extends TestCase {
 
  public void testSerializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Class[] {ITestBean.class});
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    assertEquals(1, ptm.commits);

    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm =
        (CallCountingTransactionManager) serializedTi.getTransactionManager();
    assertEquals(2, serializedPtm.commits);
  }
View Full Code Here

  public void testTransactionAttributeOnMethod() throws Exception {
    BeanFactory bf = getBeanFactory();
    ITestBean test = (ITestBean) bf.getBean("test");

    CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
    OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
    assertEquals(0, txc.getCountingBeforeAdvice().getCalls());

    assertEquals(0, txMan.commits);
    assertEquals("Initial value was correct", 4, test.getAge());
View Full Code Here

   */
  public void testRollbackRulesOnMethodCauseRollback() throws Exception {
    BeanFactory bf = getBeanFactory();
    Rollback rb = (Rollback) bf.getBean("rollback");

    CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
    OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
    assertEquals(0, txc.getCountingBeforeAdvice().getCalls());

    assertEquals(0, txMan.commits);
    rb.echoException(null);
View Full Code Here

  public void testRollbackRulesOnMethodPreventRollback() throws Exception {
    BeanFactory bf = getBeanFactory();
    Rollback rb = (Rollback) bf.getBean("rollback");

    CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);

    assertEquals(0, txMan.commits);
    // Should NOT roll back on ServletException
    try {
      rb.echoException(new ServletException());
View Full Code Here

  public void testProgrammaticRollback() throws Exception {
    BeanFactory bf = getBeanFactory();

    Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
    assertTrue(bean instanceof CallCountingTransactionManager);
    CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);

    Rollback rb = (Rollback) bf.getBean("rollback");
    assertEquals(0, txMan.commits);
    rb.rollbackOnly(false);
    assertEquals("Transaction counts match", 1, txMan.commits);
View Full Code Here

    ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
    assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
    String newName = "Gordon";
   
    // Install facade
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    PlatformTransactionManagerFacade.delegate = ptm;
   
    ini.setName(newName);
    assertEquals(newName, ini.getName());
    assertEquals(2, ptm.commits);   
View Full Code Here

  /**
   * Test that we can set the target to a dynamic TargetSource.
   */
  public void testDynamicTargetSource() throws NoSuchMethodException {
    // Install facade
    CallCountingTransactionManager txMan = new CallCountingTransactionManager();
    PlatformTransactionManagerFacade.delegate = txMan;
   
    TestBean tb = (TestBean) factory.getBean("hotSwapped");
    assertEquals(666, tb.getAge());
    int newAge = 557;
View Full Code Here

TOP

Related Classes of org.springframework.transaction.CallCountingTransactionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.