KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > oscache > extra > TestCacheEntryEventListenerImpl


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

5 package com.opensymphony.oscache.extra;
6
7 import com.opensymphony.oscache.base.Cache;
8 import com.opensymphony.oscache.base.CacheEntry;
9 import com.opensymphony.oscache.base.events.CacheEntryEvent;
10 import com.opensymphony.oscache.base.events.CacheGroupEvent;
11 import com.opensymphony.oscache.base.events.CachePatternEvent;
12 import com.opensymphony.oscache.general.GeneralCacheAdministrator;
13
14 import junit.framework.Test;
15 import junit.framework.TestCase;
16 import junit.framework.TestSuite;
17
18 /**
19  * Test the cache entry event listener implementation
20  *
21  * $Id: TestCacheEntryEventListenerImpl.java,v 1.1 2005/06/17 05:07:07 dres Exp $
22  * @version $Revision: 1.1 $
23  * @author <a HREF="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
24  */

25 public class TestCacheEntryEventListenerImpl extends TestCase {
26     /**
27      * Key used for this test
28      */

29     private final String JavaDoc KEY = "Test Cache Entry Event Listener Impl Key";
30
31     /**
32      * Constructor
33      * <p>
34      * @param str The test name (required by JUnit)
35      */

36     public TestCacheEntryEventListenerImpl(String JavaDoc str) {
37         super(str);
38     }
39
40     /**
41      * This methods returns the name of this test class to JUnit
42      * <p>
43      * @return The name of this class
44      */

45     public static Test suite() {
46         return new TestSuite(TestCacheEntryEventListenerImpl.class);
47     }
48
49     /**
50      * Test the basic implementation
51      */

52     public void testCacheEntryEventListenerImpl() {
53         // Construct the objects required for the tests
54
CacheEntry entry = new CacheEntry(KEY);
55         GeneralCacheAdministrator admin = new GeneralCacheAdministrator();
56         Cache cache = new Cache(admin.isMemoryCaching(), admin.isUnlimitedDiskCache(), admin.isOverflowPersistence());
57         CacheEntryEvent event = new CacheEntryEvent(cache, entry, null);
58         CacheEntryEventListenerImpl listener = new CacheEntryEventListenerImpl();
59
60         // Assert the counters
61
assertEquals(listener.getEntryAddedCount(), 0);
62         assertEquals(listener.getEntryFlushedCount(), 0);
63         assertEquals(listener.getEntryRemovedCount(), 0);
64         assertEquals(listener.getEntryUpdatedCount(), 0);
65         assertEquals(listener.getGroupFlushedCount(), 0);
66         assertEquals(listener.getPatternFlushedCount(), 0);
67
68         // Generate an event of each type
69
listener.cacheEntryAdded(event);
70         listener.cacheEntryFlushed(event);
71         listener.cacheEntryRemoved(event);
72         listener.cacheEntryUpdated(event);
73
74         listener.cacheGroupFlushed(new CacheGroupEvent(cache, "testGroup", null));
75         listener.cachePatternFlushed(new CachePatternEvent(cache, "testPattern", null));
76
77         // Assert the counters
78
assertEquals(listener.getEntryAddedCount(), 1);
79         assertEquals(listener.getEntryFlushedCount(), 1);
80         assertEquals(listener.getEntryRemovedCount(), 1);
81         assertEquals(listener.getEntryUpdatedCount(), 1);
82         assertEquals(listener.getGroupFlushedCount(), 1);
83         assertEquals(listener.getPatternFlushedCount(), 1);
84     }
85 }
86
Popular Tags