[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/event ...
Ben Wang
bwang at jboss.com
Fri Jul 28 05:16:14 EDT 2006
User: bwang
Date: 06/07/28 05:16:14
Modified: tests-50/functional/org/jboss/cache/pojo/event
LocalTest.java
Added: tests-50/functional/org/jboss/cache/pojo/event
ListTest.java MapTest.java SetTest.java
Log:
added event notification tests.
Revision Changes Path
1.5 +0 -1 JBossCache/tests-50/functional/org/jboss/cache/pojo/event/LocalTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/event/LocalTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LocalTest.java 27 Jul 2006 14:48:12 -0000 1.4
+++ LocalTest.java 28 Jul 2006 09:16:14 -0000 1.5
@@ -18,7 +18,6 @@
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.pojo.test.Address;
-import java.util.Map;
import java.lang.reflect.Field;
/**
1.1 date: 2006/07/28 09:16:14; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/event/ListTest.java
Index: ListTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.event;
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.PojoCacheListener;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.pojo.test.Address;
import java.lang.reflect.Field;
import java.util.ArrayList;
/**
*
* @author Ben Wang
*/
public class ListTest extends TestCase
{
Log log_ = LogFactory.getLog(ListTest.class);
PojoCache cache_;
static Throwable ex1_;
static boolean pre_;
static boolean post_;
static int counter_;
public ListTest(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();
reset();
}
private void reset()
{
ListTest.ex1_ = null;
ListTest.pre_ = false;
ListTest.post_ = false;
ListTest.counter_ = 0;
}
protected void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
// public void testDummy() {}
public void testAttachNotification1() throws Exception
{
log_.info("testAttachNotification1() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
ArrayList list = new ArrayList();
list.add("test1");
list.add("test2");
cache_.attach("a", list);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, ListTest.counter_);
list = (ArrayList)cache_.find("a");
list.remove("test2");
list.add("test3");
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, ListTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification2() throws Exception
{
log_.info("testAttachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
list.add("Taiwanese");
test.setLanguages(list);
MyListener listener = new MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
assertEquals("Total number of event is ", 4, ListTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification3() throws Exception
{
log_.info("testAttachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
ArrayList list = new ArrayList();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
list.add(addr1);
list.add(addr2);
cache_.attach("a", list);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, ListTest.counter_);
listener.reset();
list = (ArrayList)cache_.find("a");
list.remove(addr2);
Address addr3 = new Address();
addr3.setCity("Taipei");
list.add(addr3);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, ListTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification1() throws Exception
{
log_.info("testDetachNotification1() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
ArrayList list = new ArrayList();
list.add("test1");
list.add("test2");
cache_.attach("a", list);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, ListTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, ListTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification2() throws Exception
{
log_.info("testDetachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
ArrayList list = new ArrayList();
list.add("English");
list.add("Taiwanese");
test.setLanguages(list);
MyListener listener = new MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
assertEquals("Total number of event is ", 4, ListTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
assertEquals("Total number of event is ", 4, ListTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification3() throws Exception
{
log_.info("testDetachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
ArrayList list = new ArrayList();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
list.add(addr1);
list.add(addr2);
cache_.attach("a", list);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, ListTest.counter_);
listener.reset();
list = (ArrayList)cache_.find("a");
list.remove(addr2);
Address addr3 = new Address();
addr3.setCity("Taipei");
list.add(addr3);
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, ListTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + ListTest.ex1_, ListTest.ex1_);
assertTrue("pre-attach event is not emitted", ListTest.pre_);
assertTrue("post-attach event is not emitted", ListTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, ListTest.counter_);
cache_.removeListener(listener);
}
public static Test suite() throws Exception
{
return new TestSuite(ListTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(ListTest.suite());
}
public class MyListener implements PojoCacheListener
{
public MyListener()
{
}
public void reset()
{
ListTest.pre_ = false;
ListTest.post_ = false;
ListTest.counter_ = 0;
}
public void attach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
ListTest.pre_ = true;
ListTest.counter_++;
} else
{
ListTest.post_ = true;
ListTest.counter_++;
}
}
public void detach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
ListTest.pre_ = true;
ListTest.counter_++;
} else
{
ListTest.post_ = true;
ListTest.counter_++;
}
}
public void modify(Object pojo, Field field, boolean pre, boolean isLocal)
{
if(pre)
{
ListTest.pre_ = true;
ListTest.counter_++;
} else
{
ListTest.post_ = true;
ListTest.counter_++;
}
}
public void passivate(Object pojo, boolean pre)
{
throw new RuntimeException("passivate event not yet supported.");
}
public void evict(Object pojo, boolean pre)
{
throw new RuntimeException("evict event not yet supported.");
}
public void activate(Object pojo, boolean pre)
{
throw new RuntimeException("activate event not yet supported.");
}
}
}
1.1 date: 2006/07/28 09:16:14; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/event/MapTest.java
Index: MapTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.event;
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.PojoCacheListener;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.pojo.test.Address;
import java.util.HashMap;
import java.util.Map;
import java.lang.reflect.Field;
/**
*
* @author Ben Wang
*/
public class MapTest extends TestCase
{
Log log_ = LogFactory.getLog(MapTest.class);
PojoCache cache_;
static Throwable ex1_;
static boolean pre_;
static boolean post_;
static int counter_;
public MapTest(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();
reset();
}
private void reset()
{
MapTest.ex1_ = null;
MapTest.pre_ = false;
MapTest.post_ = false;
MapTest.counter_ = 0;
}
protected void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
// public void testDummy() {}
public void testAttachNotification1() throws Exception
{
log_.info("testAttachNotification1() ....");
MapTest.MyListener listener = new MapTest.MyListener();
cache_.addListener(listener);
Map map = new HashMap();
map.put("test1","test1");
map.put("test2","test2");
cache_.attach("a", map);
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, MapTest.counter_);
map = (Map)cache_.find("a");
map.remove("test2");
map.put("test3", "test3");
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, MapTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification2() throws Exception
{
log_.info("testAttachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("test1", "English");
map.put("test2", "Taiwanese");
test.setHobbies(map);
MapTest.MyListener listener = new MapTest.MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
assertEquals("Total number of event is ", 4, MapTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification3() throws Exception
{
log_.info("testAttachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
Map map = new HashMap();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
map.put("1", addr1);
map.put("2", addr2);
cache_.attach("a", map);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, MapTest.counter_);
listener.reset();
map = (Map)cache_.find("a");
map.remove("2");
Address addr3 = new Address();
addr3.setCity("Taipei");
map.put("3", addr3);
assertNull("Exception should be null but " + ListTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, MapTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification1() throws Exception
{
log_.info("testDetachNotification1() ....");
MapTest.MyListener listener = new MapTest.MyListener();
cache_.addListener(listener);
HashMap map = new HashMap();
map.put("test1", "test1");
map.put("test2", "test2");
cache_.attach("a", map);
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, MapTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, MapTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification2() throws Exception
{
log_.info("testDetachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashMap map = new HashMap();
map.put("test1", "English");
map.put("test2", "Taiwanese");
test.setHobbies(map);
MapTest.MyListener listener = new MapTest.MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
assertEquals("Total number of event is ", 4, MapTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + MapTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
assertEquals("Total number of event is ", 4, MapTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification3() throws Exception
{
log_.info("testAttachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
Map map = new HashMap();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
map.put("1", addr1);
map.put("2", addr2);
cache_.attach("a", map);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, MapTest.counter_);
listener.reset();
map = (Map)cache_.find("a");
map.remove("2");
Address addr3 = new Address();
addr3.setCity("Taipei");
map.put("3", addr3);
assertNull("Exception should be null but " + ListTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, MapTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + ListTest.ex1_, MapTest.ex1_);
assertTrue("pre-attach event is not emitted", MapTest.pre_);
assertTrue("post-attach event is not emitted", MapTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, MapTest.counter_);
cache_.removeListener(listener);
}
public static Test suite() throws Exception
{
return new TestSuite(MapTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(MapTest.suite());
}
public class MyListener implements PojoCacheListener
{
public MyListener()
{
}
public void reset()
{
MapTest.pre_ = false;
MapTest.post_ = false;
MapTest.counter_ = 0;
}
public void attach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
MapTest.pre_ = true;
MapTest.counter_++;
} else
{
MapTest.post_ = true;
MapTest.counter_++;
}
}
public void detach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
MapTest.pre_ = true;
MapTest.counter_++;
} else
{
MapTest.post_ = true;
MapTest.counter_++;
}
}
public void modify(Object pojo, Field field, boolean pre, boolean isLocal)
{
if(pre)
{
MapTest.pre_ = true;
MapTest.counter_++;
} else
{
MapTest.post_ = true;
MapTest.counter_++;
}
}
public void passivate(Object pojo, boolean pre)
{
throw new RuntimeException("passivate event not yet supported.");
}
public void evict(Object pojo, boolean pre)
{
throw new RuntimeException("evict event not yet supported.");
}
public void activate(Object pojo, boolean pre)
{
throw new RuntimeException("activate event not yet supported.");
}
}
}
1.1 date: 2006/07/28 09:16:14; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/event/SetTest.java
Index: SetTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.event;
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.PojoCacheListener;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.pojo.test.Address;
import java.util.Set;
import java.util.HashSet;
import java.lang.reflect.Field;
/**
*
* @author Ben Wang
*/
public class SetTest extends TestCase
{
Log log_ = LogFactory.getLog(SetTest.class);
PojoCache cache_;
static Throwable ex1_;
static boolean pre_;
static boolean post_;
static int counter_;
public SetTest(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();
reset();
}
private void reset()
{
SetTest.ex1_ = null;
SetTest.pre_ = false;
SetTest.post_ = false;
SetTest.counter_ = 0;
}
protected void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
// public void testDummy() {}
public void testAttachNotification1() throws Exception
{
log_.info("testAttachNotification1() ....");
SetTest.MyListener listener = new SetTest.MyListener();
cache_.addListener(listener);
Set set = new HashSet();
set.add("test1");
set.add("test2");
cache_.attach("a", set);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, SetTest.counter_);
set = (Set)cache_.find("a");
set.remove("test2");
set.add("test3");
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, SetTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification2() throws Exception
{
log_.info("testAttachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
set.add("Taiwanese");
test.setSkills(set);
SetTest.MyListener listener = new SetTest.MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
assertEquals("Total number of event is ", 4, SetTest.counter_);
cache_.removeListener(listener);
}
public void testAttachNotification3() throws Exception
{
log_.info("testAttachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
Set set = new HashSet();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
set.add(addr1);
set.add(addr2);
cache_.attach("a", set);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, SetTest.counter_);
listener.reset();
set = (Set)cache_.find("a");
set.remove(addr2);
Address addr3 = new Address();
addr3.setCity("Taipei");
set.add(addr3);
assertNull("Exception should be null but " + ListTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, SetTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification1() throws Exception
{
log_.info("testDetachNotification1() ....");
SetTest.MyListener listener = new SetTest.MyListener();
cache_.addListener(listener);
HashSet set = new HashSet();
set.add("test1");
set.add("test2");
cache_.attach("a", set);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, SetTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 2, SetTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification2() throws Exception
{
log_.info("testDetachNotification2() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
HashSet set = new HashSet();
set.add("English");
set.add("Taiwanese");
test.setSkills(set);
SetTest.MyListener listener = new SetTest.MyListener();
cache_.addListener(listener);
cache_.attach("a", test);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
assertEquals("Total number of event is ", 4, SetTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
assertEquals("Total number of event is ", 4, SetTest.counter_);
cache_.removeListener(listener);
}
public void testDetachNotification3() throws Exception
{
log_.info("testAttachNotification3() ....");
MyListener listener = new MyListener();
cache_.addListener(listener);
Set set = new HashSet();
Address addr1 = new Address();
addr1.setCity("Taipei");
Address addr2 = new Address();
addr2.setCity("Taipei");
set.add(addr1);
set.add(addr2);
cache_.attach("a", set);
assertNull("Exception should be null but " + SetTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, SetTest.counter_);
listener.reset();
set = (Set)cache_.find("a");
set.remove(addr2);
Address addr3 = new Address();
addr3.setCity("Taipei");
set.add(addr3);
assertNull("Exception should be null but " + ListTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 4, SetTest.counter_);
listener.reset();
cache_.detach("a");
assertNull("Exception should be null but " + ListTest.ex1_, SetTest.ex1_);
assertTrue("pre-attach event is not emitted", SetTest.pre_);
assertTrue("post-attach event is not emitted", SetTest.post_);
// If not a POJO just a String, we should not emit the event.
assertEquals("Total number of event is ", 6, SetTest.counter_);
cache_.removeListener(listener);
}
public static Test suite() throws Exception
{
return new TestSuite(SetTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(SetTest.suite());
}
public class MyListener implements PojoCacheListener
{
public MyListener()
{
}
public void reset()
{
SetTest.pre_ = false;
SetTest.post_ = false;
SetTest.counter_ = 0;
}
public void attach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
SetTest.pre_ = true;
SetTest.counter_++;
} else
{
SetTest.post_ = true;
SetTest.counter_++;
}
}
public void detach(Object pojo, boolean pre, boolean isLocal)
{
if(pre)
{
SetTest.pre_ = true;
SetTest.counter_++;
} else
{
SetTest.post_ = true;
SetTest.counter_++;
}
}
public void modify(Object pojo, Field field, boolean pre, boolean isLocal)
{
if(pre)
{
SetTest.pre_ = true;
SetTest.counter_++;
} else
{
SetTest.post_ = true;
SetTest.counter_++;
}
}
public void passivate(Object pojo, boolean pre)
{
throw new RuntimeException("passivate event not yet supported.");
}
public void evict(Object pojo, boolean pre)
{
throw new RuntimeException("evict event not yet supported.");
}
public void activate(Object pojo, boolean pre)
{
throw new RuntimeException("activate event not yet supported.");
}
}
}
More information about the jboss-cvs-commits
mailing list