[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback ...
Ben Wang
bwang at jboss.com
Sun Jul 30 21:49:30 EDT 2006
User: bwang
Date: 06/07/30 21:49:30
Added: tests-50/functional/org/jboss/cache/pojo/rollback
ListTxUndoTest.java ListUndoTest.java
LocalTxUndoTest.java LocalUndoTest.java
MapTxUndoTest.java MapUndoTest.java
SetTxUndoTest.java SetUndoTest.java
Log:
Test cases for undo operation.
Revision Changes Path
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/ListTxUndoTest.java
Index: ListTxUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class ListTxUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(ListTxUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public ListTxUndoTest(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 testSimple() throws Exception
{
ArrayList list = new ArrayList();
list.add("test1");
tx_mgr.begin();
cache_.attach("/a", list);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(list));
cache_.attach("/a", list);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
test.setLanguages(list);
tx_mgr.begin();
cache_.attach("/a", test);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getLanguages()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
test.setLanguages(list);
cache_.attach("/a", test);
tx_mgr.begin();
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertTrue("Should still have cache interceptor ", isProxy(test.getLanguages()));
cache_.detach("/a");
}
public void testSimpleTxWithRollback3() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
test.setLanguages(list);
tx_mgr.begin();
cache_.attach("/a", test);
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getLanguages()));
}
public static Test suite() throws Exception
{
return new TestSuite(ListTxUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(ListTxUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/ListUndoTest.java
Index: ListUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class ListUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(ListUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public ListUndoTest(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() {}
private void setTxRollback(boolean isTrue)
{
PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
}
public void testSimple() throws Exception
{
ArrayList list = new ArrayList();
list.add("test1");
setTxRollback(true);
cache_.attach("/a", list);
assertFalse("Should not have cache interceptor ", isProxy(list));
cache_.attach("/a", list);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
test.setLanguages(list);
setTxRollback(true);
cache_.attach("/a", test);
assertFalse("Should not have cache interceptor ", isProxy(test.getLanguages()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
test.setLanguages(list);
cache_.attach("/a", test);
setTxRollback(true);
cache_.detach("/a");
assertTrue("Should still have cache interceptor ", isProxy(test.getLanguages()));
cache_.detach("/a");
}
public static Test suite() throws Exception
{
return new TestSuite(ListUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(ListUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/LocalTxUndoTest.java
Index: LocalTxUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
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 LocalTxUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(LocalTxUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public LocalTxUndoTest(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));
cache_.attach("/a", test);
}
private boolean hasCacheInterceptor(Object pojo)
{
Interceptor[] interceptors = ((Advised)pojo)._getInstanceAdvisor().getInterceptors();
for(int i=0; i < interceptors.length; i++)
{
if(interceptors[i] instanceof CacheFieldInterceptor)
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));
cache_.detach("/a");
}
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(LocalTxUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(LocalTxUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/LocalUndoTest.java
Index: LocalUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.Advised;
import javax.transaction.TransactionManager;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class LocalUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(LocalUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public LocalUndoTest(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() {}
private void setTxRollback(boolean isTrue)
{
PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
setTxRollback(true);
cache_.attach("/a", test);
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 CacheFieldInterceptor)
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);
setTxRollback(true);
cache_.detach("/a");
assertTrue("Should still have cache interceptor ", hasCacheInterceptor(test));
}
public static Test suite() throws Exception
{
return new TestSuite(LocalUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(LocalUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/MapTxUndoTest.java
Index: MapTxUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class MapTxUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(MapTxUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public MapTxUndoTest(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 testSimple() throws Exception
{
HashMap map = new HashMap();
map.put("1", "test1");
tx_mgr.begin();
cache_.attach("/a", map);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(map));
cache_.attach("/a", map);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("1", "English");
test.setHobbies(map);
tx_mgr.begin();
cache_.attach("/a", test);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getHobbies()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("1", "English");
test.setHobbies(map);
cache_.attach("/a", test);
tx_mgr.begin();
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertTrue("Should still have cache interceptor ", isProxy(test.getHobbies()));
cache_.detach("/a");
}
public void testSimpleTxWithRollback3() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("1", "English");
test.setHobbies(map);
tx_mgr.begin();
cache_.attach("/a", test);
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getHobbies()));
}
public static Test suite() throws Exception
{
return new TestSuite(MapTxUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(MapTxUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/MapUndoTest.java
Index: MapUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.HashMap;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class MapUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(MapUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public MapUndoTest(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() {}
private void setTxRollback(boolean isTrue)
{
PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
}
public void testSimple() throws Exception
{
HashMap map = new HashMap();
map.put("1", "test1");
setTxRollback(true);
cache_.attach("/a", map);
assertFalse("Should not have cache interceptor ", isProxy(map));
cache_.attach("/a", map);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("1", "English");
test.setHobbies(map);
setTxRollback(true);
cache_.attach("/a", test);
assertFalse("Should not have cache interceptor ", isProxy(test.getHobbies()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("1", "English");
test.setHobbies(map);
cache_.attach("/a", test);
setTxRollback(true);
cache_.detach("/a");
assertTrue("Should still have cache interceptor ", isProxy(test.getHobbies()));
cache_.detach("/a");
}
public static Test suite() throws Exception
{
return new TestSuite(MapUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(MapUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/SetTxUndoTest.java
Index: SetTxUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
import java.util.HashSet;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class SetTxUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(SetTxUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public SetTxUndoTest(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 testSimple() throws Exception
{
HashSet set = new HashSet();
set.add("test1");
tx_mgr.begin();
cache_.attach("/a", set);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(set));
cache_.attach("/a", set);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
test.setSkills(set);
tx_mgr.begin();
cache_.attach("/a", test);
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getSkills()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
test.setSkills(set);
cache_.attach("/a", test);
tx_mgr.begin();
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertTrue("Should still have cache interceptor ", isProxy(test.getSkills()));
cache_.detach("/a");
}
public void testSimpleTxWithRollback3() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
test.setSkills(set);
tx_mgr.begin();
cache_.attach("/a", test);
cache_.detach("/a");
tx_mgr.getTransaction().rollback();
assertFalse("Should not have cache interceptor ", isProxy(test.getSkills()));
}
public static Test suite() throws Exception
{
return new TestSuite(SetTxUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(SetTxUndoTest.suite());
}
}
1.1 date: 2006/07/31 01:49:30; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/rollback/SetUndoTest.java
Index: SetUndoTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.rollback;
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.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.aop.proxy.ClassProxy;
import javax.transaction.TransactionManager;
import java.util.HashSet;
/**
* Additional basic tests
*
* @author Ben Wang
*/
public class SetUndoTest extends TestCase
{
Log log_ = LogFactory.getLog(SetUndoTest.class);
PojoCache cache_;
TransactionManager tx_mgr;
public SetUndoTest(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() {}
private void setTxRollback(boolean isTrue)
{
PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
}
public void testSimple() throws Exception
{
HashSet set = new HashSet();
set.add("test1");
setTxRollback(true);
cache_.attach("/a", set);
assertFalse("Should not have cache interceptor ", isProxy(set));
cache_.attach("/a", set);
}
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
test.setSkills(set);
setTxRollback(true);
cache_.attach("/a", test);
assertFalse("Should not have cache interceptor ", isProxy(test.getSkills()));
cache_.attach("/a", test);
}
private boolean isProxy(Object pojo)
{
if(pojo instanceof ClassProxy) return true;
return false;
}
public void testSimpleTxWithRollback2() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
test.setSkills(set);
cache_.attach("/a", test);
setTxRollback(true);
cache_.detach("/a");
assertTrue("Should still have cache interceptor ", isProxy(test.getSkills()));
cache_.detach("/a");
}
public static Test suite() throws Exception
{
return new TestSuite(SetUndoTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(SetUndoTest.suite());
}
}
More information about the jboss-cvs-commits
mailing list