01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: /*
06: * Created on Mar 11, 2005
07: *
08: * TODO To change the template for this generated file go to
09: * Window - Preferences - Java - Code Style - Code Templates
10: */
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: /**
22: * @author admin
23: *
24: * TODO To change the template for this generated type comment go to
25: * Window - Preferences - Java - Code Style - Code Templates
26: */
27: public class TestUnSerializable extends TestCase {
28: final String CACHE_DIRECTORY_PATH = TestDiskPersistenceListener.CACHEDIR
29: + "/application";
30: GeneralCacheAdministrator cache;
31:
32: /* (non-Javadoc)
33: * @see junit.framework.TestCase#setUp()
34: */
35: protected void setUp() throws Exception {
36: // TODO Auto-generated method stub
37: super .setUp();
38:
39: java.util.Properties properties = new java.util.Properties();
40: properties.setProperty("cache.path",
41: TestDiskPersistenceListener.CACHEDIR);
42: properties
43: .setProperty("cache.persistence.class",
44: "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener");
45: properties.setProperty("cache.persistence.overflow.only",
46: "true");
47:
48: // properties.setProperty("cache.memory", "false");
49: properties.setProperty("cache.capacity", "2");
50: properties.setProperty("cache.unlimited.disk", "false");
51: cache = new GeneralCacheAdministrator(properties);
52: cache.getCache().getPersistenceListener().clear();
53: }
54:
55: /* (non-Javadoc)
56: * @see junit.framework.TestCase#tearDown()
57: */
58: protected void tearDown() throws Exception {
59: // TODO Auto-generated method stub
60: super .tearDown();
61: }
62:
63: public void testNotSerializableObject() throws Exception {
64: cache.putInCache("1", new UnSerializable());
65: cache.putInCache("2", new UnSerializable());
66: assertTrue(isDirectoryEmpty(CACHE_DIRECTORY_PATH));
67: cache.putInCache("3", new UnSerializable());
68: cache.putInCache("4", new UnSerializable());
69: assertTrue(isDirectoryEmpty(CACHE_DIRECTORY_PATH));
70: cache.flushAll();
71: }
72:
73: /**
74: * @param filePath
75: * @return
76: */
77: private boolean isDirectoryEmpty(String filePath) {
78: File file = new File(filePath);
79: return !file.exists() || (file.list().length == 0);
80: }
81:
82: /**
83: * This methods returns the name of this test class to JUnit
84: * <p>
85: * @return The test for this class
86: */
87: public static Test suite() {
88: return new TestSuite(TestUnSerializable.class);
89: }
90:
91: public static class UnSerializable {
92: int asdfasdfasdf = 234;
93: }
94: }
|