1 5 11 package com.opensymphony.oscache.plugins.diskpersistence; 12 13 import com.opensymphony.oscache.general.GeneralCacheAdministrator; 14 15 import junit.framework.Test; 16 import junit.framework.TestCase; 17 import junit.framework.TestSuite; 18 19 import java.io.File ; 20 21 27 public class TestUnSerializable extends TestCase { 28 final String CACHE_DIRECTORY_PATH = TestDiskPersistenceListener.CACHEDIR + "/application"; 29 GeneralCacheAdministrator cache; 30 31 34 protected void setUp() throws Exception { 35 super.setUp(); 37 38 java.util.Properties properties = new java.util.Properties (); 39 properties.setProperty("cache.path", TestDiskPersistenceListener.CACHEDIR); 40 properties.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener"); 41 properties.setProperty("cache.persistence.overflow.only", "true"); 42 43 properties.setProperty("cache.capacity", "2"); 45 properties.setProperty("cache.unlimited.disk", "false"); 46 cache = new GeneralCacheAdministrator(properties); 47 cache.getCache().getPersistenceListener().clear(); 48 } 49 50 53 protected void tearDown() throws Exception { 54 super.tearDown(); 56 } 57 58 public void testNotSerializableObject() throws Exception { 59 cache.putInCache("1", new UnSerializable()); 60 cache.putInCache("2", new UnSerializable()); 61 assertTrue(isDirectoryEmpty(CACHE_DIRECTORY_PATH)); 62 cache.putInCache("3", new UnSerializable()); 63 cache.putInCache("4", new UnSerializable()); 64 assertTrue(isDirectoryEmpty(CACHE_DIRECTORY_PATH)); 65 cache.flushAll(); 66 } 67 68 72 private boolean isDirectoryEmpty(String filePath) { 73 File file = new File (filePath); 74 return !file.exists() || (file.list().length == 0); 75 } 76 77 82 public static Test suite() { 83 return new TestSuite(TestUnSerializable.class); 84 } 85 86 public static class UnSerializable { 87 int asdfasdfasdf = 234; 88 } 89 } 90 | Popular Tags |