From 7ec80867437a0a14f33a210e5f5c57b1b82e40f1 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Fri, 19 Oct 2007 19:32:36 +0000 Subject: [PATCH] Add tests of Region.toMap() git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14124 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../AbstractGeneralDataRegionTestCase.java | 11 +++++++ .../jbc2/AbstractRegionImplTestCase.java | 29 ++++++++++++++++++- .../CollectionRegionImplTestCase.java | 12 +++++++- .../jbc2/entity/EntityRegionImplTestCase.java | 11 +++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java index 28b571b4a8..7d76d5d39e 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java @@ -21,6 +21,7 @@ import java.util.Set; import org.hibernate.cache.GeneralDataRegion; import org.hibernate.cache.QueryResultsRegion; +import org.hibernate.cache.Region; import org.hibernate.cache.jbc2.JBossCacheRegionFactory; import org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory; import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager; @@ -50,6 +51,16 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm super(name); } + @Override + protected void putInRegion(Region region, Object key, Object value) { + ((GeneralDataRegion) region).put(key, value); + } + + @Override + protected void removeFromRegion(Region region, Object key) { + ((GeneralDataRegion) region).evict(key); + } + /** * Test method for {@link QueryResultsRegion#evict(java.lang.Object)}. * diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java index cdf5bb6cb4..f0fcf79193 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractRegionImplTestCase.java @@ -16,6 +16,7 @@ package org.hibernate.test.cache.jbc2; +import java.util.Map; import java.util.Properties; import org.hibernate.cache.CacheDataDescription; @@ -109,14 +110,40 @@ public abstract class AbstractRegionImplTestCase extends AbstractJBossCacheTestC assertNull("No region node", localCache.getRoot().getChild( regionFqn )); } + public void testToMap() throws Exception { + Configuration cfg = CacheTestUtil.buildConfiguration("test", SharedJBossCacheRegionFactory.class, true, true); + JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); + + Region region = createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription()); + + putInRegion(region, "key1", "value1"); + putInRegion(region, "key2", "value2"); + + Map map = region.toMap(); + assertNotNull(map); + assertEquals(2, map.size()); + assertEquals("value1", map.get("key1")); + assertEquals("value2", map.get("key2")); + + removeFromRegion(region, "key1"); + + map = region.toMap(); + assertNotNull(map); + assertEquals(1, map.size()); + assertEquals("value2", map.get("key2")); + } + protected abstract Cache getJBossCache(JBossCacheRegionFactory regionFactory); protected abstract Fqn getRegionFqn(String regionName, String regionPrefix); protected abstract Region createRegion(JBossCacheRegionFactory regionFactory, String regionName, Properties properties, CacheDataDescription cdd); + protected abstract void putInRegion(Region region, Object key, Object value); + protected abstract void removeFromRegion(Region region, Object key); + protected CacheDataDescription getCacheDataDescription() { return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE); - } + } } diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/CollectionRegionImplTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/CollectionRegionImplTestCase.java index 86f5886ba8..7db1fe1ee6 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/CollectionRegionImplTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/CollectionRegionImplTestCase.java @@ -49,6 +49,7 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion super(name); } + @Override protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) { CollectionRegion region = regionFactory.buildCollectionRegion("test", properties, null); @@ -92,6 +93,15 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion protected Fqn getRegionFqn(String regionName, String regionPrefix) { return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, CollectionRegionImpl.TYPE); } - + + @Override + protected void putInRegion(Region region, Object key, Object value) { + ((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).putFromLoad(key, value, System.currentTimeMillis(), new Integer(1)); + } + + @Override + protected void removeFromRegion(Region region, Object key) { + ((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key); + } } diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/EntityRegionImplTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/EntityRegionImplTestCase.java index 4cd32f5fe9..5cc0834026 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/EntityRegionImplTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/EntityRegionImplTestCase.java @@ -49,6 +49,7 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest super(name); } + @Override protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) { EntityRegion region = regionFactory.buildEntityRegion("test", properties, null); @@ -93,6 +94,16 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest protected Fqn getRegionFqn(String regionName, String regionPrefix) { return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, EntityRegionImpl.TYPE); } + + @Override + protected void putInRegion(Region region, Object key, Object value) { + ((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).insert(key, value, new Integer(1)); + } + + @Override + protected void removeFromRegion(Region region, Object key) { + ((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key); + } }