Source Code Cross Referenced for TestCacheEntry.java in  » Cache » OSCache » com » opensymphony » oscache » base » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.base;
006:
007:        import junit.framework.Test;
008:        import junit.framework.TestCase;
009:        import junit.framework.TestSuite;
010:
011:        /**
012:         * Test the public methods of the CacheEntry class
013:         *
014:         * $Id: TestCacheEntry.java 254 2005-06-17 05:07:38Z dres $
015:         * @version        $Revision: 254 $
016:         * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
017:         */
018:        public class TestCacheEntry extends TestCase {
019:            // Static variables required thru the tests
020:            static CacheEntry entry = null;
021:            static long beforeCreation = 0;
022:            static long afterCreation = 0;
023:            private final String CONTENT = "Content for the cache entry test";
024:
025:            // Constants used thru the tests
026:            private final String ENTRY_KEY = "Test cache entry key";
027:            private final int NO_REFRESH_NEEDED = 1000000;
028:            private final int REFRESH_NEEDED = 0;
029:
030:            /**
031:             * Class constructor
032:             * <p>
033:             * @param str The test name (required by JUnit)
034:             */
035:            public TestCacheEntry(String str) {
036:                super (str);
037:            }
038:
039:            /**
040:             * This method is invoked before each testXXXX methods of the
041:             * class. It set ups the variables required for each tests.
042:             */
043:            public void setUp() {
044:                // At first invocation, create a cache entry object
045:                if (entry == null) {
046:                    // Log the time before and after to verify the creation time
047:                    // in one of the tests
048:                    beforeCreation = System.currentTimeMillis();
049:
050:                    entry = new CacheEntry(ENTRY_KEY);
051:                    afterCreation = System.currentTimeMillis();
052:                }
053:            }
054:
055:            /**
056:             * This methods returns the name of this test class to JUnit
057:             * <p>
058:             * @return The name of this class
059:             */
060:            public static Test suite() {
061:                return new TestSuite(TestCacheEntry.class);
062:            }
063:
064:            /**
065:             * Verify the flush
066:             */
067:            public void testFlush() {
068:                // Set the content so it shouldn't need refresh
069:                entry.setContent(CONTENT);
070:                assertTrue(!entry.needsRefresh(NO_REFRESH_NEEDED));
071:
072:                // Flush the entry. It should now needs refresh
073:                entry.flush();
074:                assertTrue(entry.needsRefresh(NO_REFRESH_NEEDED));
075:            }
076:
077:            /**
078:             * Verify that the creation time is correct
079:             */
080:            public void testGetCreated() {
081:                assertBetweenOrEquals(beforeCreation, entry.getCreated(),
082:                        afterCreation);
083:            }
084:
085:            /**
086:             * Retrieve the item created by the setup
087:             */
088:            public void testGetKey() {
089:                assertTrue(entry.getKey().equals(ENTRY_KEY));
090:            }
091:
092:            /**
093:             * Verify that the last modification time is between the time before and
094:             * after the alteration of the item
095:             */
096:            public void testGetLastUpdate() {
097:                // again. Then we ensure that the update time is between our timestamps
098:                long before = System.currentTimeMillis();
099:                entry.setContent(CONTENT);
100:
101:                long after = System.currentTimeMillis();
102:                assertBetweenOrEquals(before, entry.getLastUpdate(), after);
103:            }
104:
105:            /**
106:             * Verify that the "freshness detection" function properly
107:             */
108:            public void testNeedsRefresh() {
109:                // Set the entry content so it shouldn't need refresh
110:                // Invoke needsRefresh with no delay, so it should return true.
111:                // Then invoke it with a big delay, so it should return false
112:                assertTrue(entry.needsRefresh(REFRESH_NEEDED));
113:                assertTrue(!entry.needsRefresh(NO_REFRESH_NEEDED));
114:            }
115:
116:            /**
117:             * Set the content of the item created by setup and then retrieve it and
118:             * validate it
119:             */
120:            public void testSetGetContent() {
121:                entry.setContent(CONTENT);
122:                assertTrue(CONTENT.equals(entry.getContent()));
123:
124:                // Ensure that nulls are allowed
125:                entry.setContent(null);
126:                assertNull(entry.getContent());
127:            }
128:
129:            /**
130:             * Ensure that a value is between two others. Since the execution may be
131:             * very fast, equals values are also considered to be between
132:             */
133:            private void assertBetweenOrEquals(long first, long between,
134:                    long last) {
135:                assertTrue(between >= first);
136:                assertTrue(between <= last);
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.