Source Code Cross Referenced for CacheExceptionHandlerTest.java in  » Cache » ehcache » net » sf » ehcache » exceptionhandler » 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 » ehcache » net.sf.ehcache.exceptionhandler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Copyright 2003-2007 Luck Consulting Pty Ltd
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */package net.sf.ehcache.exceptionhandler;
016:
017:        import junit.framework.TestCase;
018:        import net.sf.ehcache.CacheManager;
019:        import net.sf.ehcache.Ehcache;
020:        import net.sf.ehcache.AbstractCacheTest;
021:        import net.sf.ehcache.CacheException;
022:        import net.sf.ehcache.loader.ExceptionThrowingLoader;
023:        import net.sf.ehcache.event.CountingCacheEventListener;
024:
025:        /**
026:         * @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
027:         * @version $Id: CacheExceptionHandlerTest.java 530 2007-08-06 10:21:54Z gregluck $
028:         */
029:        public class CacheExceptionHandlerTest extends TestCase {
030:
031:            /**
032:             * manager
033:             */
034:            protected CacheManager manager;
035:            /**
036:             * the cache name we wish to test
037:             */
038:            protected String cacheName = "exceptionHandlingCache";
039:            /**
040:             * the cache we wish to test                                                                
041:             */
042:            protected Ehcache cache;
043:
044:            /**
045:             * {@inheritDoc}
046:             *
047:             * @throws Exception
048:             */
049:            protected void setUp() throws Exception {
050:                CountingCacheEventListener.resetCounters();
051:                manager = CacheManager.create(AbstractCacheTest.TEST_CONFIG_DIR
052:                        + "ehcache.xml");
053:                cache = manager.getEhcache(cacheName);
054:                cache.removeAll();
055:            }
056:
057:            /**
058:             * {@inheritDoc}
059:             *
060:             * @throws Exception
061:             */
062:            protected void tearDown() throws Exception {
063:                CountingExceptionHandler.resetCounters();
064:                manager.shutdown();
065:            }
066:
067:            /**
068:             * Test a cache which has been configured to have a CountingExceptionHandler configured
069:             */
070:            public void testConfiguredCache() {
071:                manager.removeCache("exceptionHandlingCache");
072:                //Would normally throw an IllegalStateException
073:                cache.get("key1");
074:
075:                assertEquals(1, CountingExceptionHandler.HANDLED_EXCEPTIONS
076:                        .size());
077:                assertEquals(
078:                        null,
079:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
080:                                .get(0)).getKey());
081:                assertEquals(
082:                        IllegalStateException.class,
083:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
084:                                .get(0)).getException().getClass());
085:            }
086:
087:            /**
088:             * Test a cache which has been configured to have an ExceptionThrowingLoader screw up loading.
089:             * This one should have a key set.
090:             */
091:            public void testKeyWithConfiguredCache() {
092:
093:                cache.setCacheLoader(new ExceptionThrowingLoader());
094:                cache.getWithLoader("key1", null, null);
095:
096:                assertEquals(1, CountingExceptionHandler.HANDLED_EXCEPTIONS
097:                        .size());
098:                assertEquals(
099:                        "key1",
100:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
101:                                .get(0)).getKey());
102:                assertEquals(
103:                        CacheException.class,
104:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
105:                                .get(0)).getException().getClass());
106:            }
107:
108:            /**
109:             * Double proxy test
110:             */
111:            public void testCacheExceptionHandler() {
112:                Ehcache proxiedCache = ExceptionHandlingDynamicCacheProxy
113:                        .createProxy(cache);
114:
115:                //Would normally throw an IllegalArgumentException
116:                proxiedCache.put(null);
117:
118:                assertEquals(1, CountingExceptionHandler.HANDLED_EXCEPTIONS
119:                        .size());
120:                assertEquals(
121:                        null,
122:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
123:                                .get(0)).getKey());
124:                assertEquals(
125:                        IllegalArgumentException.class,
126:                        ((CountingExceptionHandler.HandledException) CountingExceptionHandler.HANDLED_EXCEPTIONS
127:                                .get(0)).getException().getClass());
128:            }
129:
130:            /**
131:             * Test some gnarly parsing code
132:             */
133:            public void testKeyExtraction() {
134:
135:                String testMessage = "For key 1234";
136:                String key = ExceptionHandlingDynamicCacheProxy
137:                        .extractKey(testMessage);
138:                assertEquals("1234", key);
139:
140:                testMessage = "key 1234";
141:                key = ExceptionHandlingDynamicCacheProxy
142:                        .extractKey(testMessage);
143:                assertEquals("1234", key);
144:
145:                testMessage = null;
146:                key = ExceptionHandlingDynamicCacheProxy
147:                        .extractKey(testMessage);
148:                assertEquals(null, key);
149:
150:                testMessage = "";
151:                key = ExceptionHandlingDynamicCacheProxy
152:                        .extractKey(testMessage);
153:                assertEquals(null, key);
154:
155:                testMessage = "key 1234 ";
156:                key = ExceptionHandlingDynamicCacheProxy
157:                        .extractKey(testMessage);
158:                assertEquals("1234", key);
159:
160:                testMessage = "key 1234 .";
161:                key = ExceptionHandlingDynamicCacheProxy
162:                        .extractKey(testMessage);
163:                assertEquals("1234", key);
164:
165:                testMessage = "key .";
166:                key = ExceptionHandlingDynamicCacheProxy
167:                        .extractKey(testMessage);
168:                assertEquals(".", key);
169:
170:                testMessage = "key";
171:                key = ExceptionHandlingDynamicCacheProxy
172:                        .extractKey(testMessage);
173:                assertEquals(null, key);
174:
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.