From: Ben W. <bw...@jb...> - 2006-07-07 09:35:25
|
User: bwang Date: 06/07/07 05:35:23 Added: tests-50/functional/org/jboss/cache/pojo TxUndoTest.java Log: Added undo interceptor stack. Revision Changes Path 1.1 date: 2006/07/07 09:35:23; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/TxUndoTest.java Index: TxUndoTest.java =================================================================== /* * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.cache.pojo; import junit.framework.TestCase; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.pojo.test.Person; import org.jboss.cache.transaction.DummyTransactionManager; import org.jboss.aop.Advised; import org.jboss.aop.advice.Interceptor; import javax.transaction.TransactionManager; /** * Additional basic tests * * @author Ben Wang */ public class TxUndoTest extends TestCase { Log log_ = LogFactory.getLog(TxUndoTest.class); PojoCache cache_; TransactionManager tx_mgr; public TxUndoTest(String name) { super(name); } protected void setUp() throws Exception { super.setUp(); log_.info("setUp() ...."); String configFile = "META-INF/local-service.xml"; cache_ = PojoCacheFactory.createInstance(configFile); cache_.start(); tx_mgr = DummyTransactionManager.getInstance(); } protected void tearDown() throws Exception { super.tearDown(); cache_.stop(); } // public void testDummy() {} public void testSimpleTxWithRollback1() throws Exception { log_.info("testSimpleTxWithRollback1() ...."); Person test = new Person(); test.setName("Ben"); test.setAge(10); tx_mgr.begin(); cache_.attach("/a", test); tx_mgr.getTransaction().rollback(); assertFalse("Should not have cache interceptor ", hasCacheInterceptor(test)); } private boolean hasCacheInterceptor(Object pojo) { Interceptor[] interceptors = ((Advised)pojo)._getInstanceAdvisor().getInterceptors(); for(int i=0; i < interceptors.length; i++) { if(interceptors[i] instanceof CacheInterceptor) return true; } return false; } public void testSimpleTxWithRollback2() throws Exception { log_.info("testSimpleTxWithRollback1() ...."); Person test = new Person(); test.setName("Ben"); test.setAge(10); cache_.attach("/a", test); tx_mgr.begin(); cache_.detach("/a"); tx_mgr.getTransaction().rollback(); assertTrue("Should still have cache interceptor ", hasCacheInterceptor(test)); } public void testSimpleTxWithRollback3() throws Exception { log_.info("testSimpleTxWithRollback1() ...."); Person test = new Person(); test.setName("Ben"); test.setAge(10); tx_mgr.begin(); cache_.attach("/a", test); cache_.detach("/a"); tx_mgr.getTransaction().rollback(); assertFalse("Should not have cache interceptor ", hasCacheInterceptor(test)); } public static Test suite() throws Exception { return new TestSuite(TxUndoTest.class); } public static void main(String[] args) throws Exception { junit.textui.TestRunner.run(TxUndoTest.suite()); } } |