KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > oscache > plugins > diskpersistence > TestUnSerializable


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 /*
6  * Created on Mar 11, 2005
7  *
8  * TODO To change the template for this generated file go to
9  * 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 JavaDoc;
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 JavaDoc CACHE_DIRECTORY_PATH = TestDiskPersistenceListener.CACHEDIR + "/application";
29     GeneralCacheAdministrator cache;
30
31     /* (non-Javadoc)
32      * @see junit.framework.TestCase#setUp()
33      */

34     protected void setUp() throws Exception JavaDoc {
35         // TODO Auto-generated method stub
36
super.setUp();
37
38         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
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.memory", "false");
44
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     /* (non-Javadoc)
51      * @see junit.framework.TestCase#tearDown()
52      */

53     protected void tearDown() throws Exception JavaDoc {
54         // TODO Auto-generated method stub
55
super.tearDown();
56     }
57
58     public void testNotSerializableObject() throws Exception JavaDoc {
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     /**
69          * @param filePath
70          * @return
71          */

72     private boolean isDirectoryEmpty(String JavaDoc filePath) {
73         File JavaDoc file = new File JavaDoc(filePath);
74         return !file.exists() || (file.list().length == 0);
75     }
76
77     /**
78     * This methods returns the name of this test class to JUnit
79     * <p>
80     * @return The test for this class
81     */

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