KickJava   Java API By Example, From Geeks To Geeks.

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


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.CacheEntry;
8 import com.opensymphony.oscache.base.events.CacheMapAccessEvent;
9 import com.opensymphony.oscache.base.events.CacheMapAccessEventType;
10
11 import junit.framework.Test;
12 import junit.framework.TestCase;
13 import junit.framework.TestSuite;
14
15 /**
16  * Test the cache map access event listener implementation
17  *
18  * $Id: TestCacheMapAccessEventListenerImpl.java,v 1.1 2005/06/17 05:07:07 dres Exp $
19  * @version $Revision: 1.1 $
20  * @author <a HREF="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
21  */

22 public class TestCacheMapAccessEventListenerImpl extends TestCase {
23     /**
24      * Key used for this test
25      */

26     private final String JavaDoc KEY = "Test Cache Map Access Event Listener Impl Key";
27
28     /**
29      * Constructor
30      * <p>
31      * @param str The test name (required by JUnit)
32      */

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

42     public static Test suite() {
43         return new TestSuite(TestCacheMapAccessEventListenerImpl.class);
44     }
45
46     /**
47      * Test the basic implementation of the listener
48      */

49     public void testCacheMapAccessEventListenerImpl() {
50         // Build objects required for the tests
51
CacheEntry entry = new CacheEntry(KEY);
52         CacheMapAccessEventListenerImpl listener = new CacheMapAccessEventListenerImpl();
53
54         // Genereate events
55
listener.accessed(new CacheMapAccessEvent(CacheMapAccessEventType.HIT, entry));
56         listener.accessed(new CacheMapAccessEvent(CacheMapAccessEventType.HIT, entry));
57         listener.accessed(new CacheMapAccessEvent(CacheMapAccessEventType.STALE_HIT, entry));
58         listener.accessed(new CacheMapAccessEvent(CacheMapAccessEventType.MISS, entry));
59
60         // Assert the counters
61
assertEquals(listener.getHitCount(), 2);
62         assertEquals(listener.getStaleHitCount(), 1);
63         assertEquals(listener.getMissCount(), 1);
64
65         // Reset the counts
66
listener.reset();
67         assertEquals(listener.getHitCount(), 0);
68         assertEquals(listener.getStaleHitCount(), 0);
69         assertEquals(listener.getMissCount(), 0);
70     }
71 }
72
Popular Tags