Source Code Cross Referenced for DozerCacheManagerTest.java in  » Database-ORM » dozer » net » sf » dozer » util » mapping » cache » 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
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » dozer » net.sf.dozer.util.mapping.cache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 the original author or authors.
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:         */
016:        package net.sf.dozer.util.mapping.cache;
017:
018:        import java.util.HashSet;
019:        import java.util.Set;
020:
021:        import net.sf.dozer.util.mapping.AbstractDozerTest;
022:        import net.sf.dozer.util.mapping.MappingException;
023:
024:        /**
025:         * @author tierney.matt
026:         */
027:        public class DozerCacheManagerTest extends AbstractDozerTest {
028:            private DozerCacheManager cacheMgr;
029:
030:            protected void setUp() throws Exception {
031:                super .setUp();
032:                cacheMgr = new DozerCacheManager();
033:            }
034:
035:            public void testCreateNew() throws Exception {
036:                DozerCacheManager cacheMgr2 = new DozerCacheManager();
037:
038:                assertFalse("cache mgrs should not be equal", cacheMgr
039:                        .equals(cacheMgr2));
040:                assertNotSame("cache mgrs should not be same instance",
041:                        cacheMgr, cacheMgr2);
042:            }
043:
044:            public void testAddGetExistsCache() throws Exception {
045:                String cacheName = getRandomString();
046:                cacheMgr.addCache(cacheName, 1);
047:
048:                boolean cacheExists = cacheMgr.cacheExists(cacheName);
049:                assertTrue("cache should exist", cacheExists);
050:
051:                Cache cache = cacheMgr.getCache(cacheName);
052:                assertNotNull("cache should not be null", cache);
053:                assertEquals("cache should be empty", cache.getSize(), 0);
054:                assertEquals("invalid cache name", cacheName, cache.getName());
055:            }
056:
057:            public void testGetUnknownCache() throws Exception {
058:                String cacheName = getRandomString();
059:                boolean cacheExists = cacheMgr.cacheExists(cacheName);
060:                assertFalse("cache should not exist", cacheExists);
061:
062:                try {
063:                    cacheMgr.getCache(cacheName);
064:                    fail("trying to get an unknown cache should have thrown a MappingException");
065:                } catch (MappingException e) {
066:                }
067:            }
068:
069:            public void testAddDuplicateCachesSingleton() throws Exception {
070:                String cacheName = getRandomString();
071:                cacheMgr.addCache(cacheName, 1);
072:
073:                try {
074:                    // try adding it again
075:                    cacheMgr.addCache(cacheName, 1);
076:                    fail("trying to add duplicate caches should have thrown an ObjectExistsException");
077:                } catch (MappingException e) {
078:                }
079:            }
080:
081:            public void testAddDuplicateCachesNonSingleton() throws Exception {
082:                // You should be able to add caches with the same name to non singleton instances
083:                // of the cache manager because they each have their own copies of caches to manage.
084:                // The caches are uniquely identified by the cache managers by using the instance id.
085:                DozerCacheManager cacheMgr2 = new DozerCacheManager();
086:
087:                // add cache to each cache mgr instance
088:                String cacheName = getRandomString();
089:                cacheMgr.addCache(cacheName, 1);
090:                cacheMgr2.addCache(cacheName, 1);
091:
092:                assertTrue("cache should exist in cache mgr1", cacheMgr
093:                        .cacheExists(cacheName));
094:                assertTrue("cache should also exist in cache mgr2", cacheMgr2
095:                        .cacheExists(cacheName));
096:
097:                Cache cache1 = cacheMgr.getCache(cacheName);
098:                Cache cache2 = cacheMgr2.getCache(cacheName);
099:
100:                assertFalse("caches should not be the same instance",
101:                        cache1 == cache2);
102:                assertEquals("invalid cache name", cacheName, cache1.getName());
103:                assertEquals("invalid cache name for cache2", cacheName, cache2
104:                        .getName());
105:            }
106:
107:            public void testGetStatisticTypes() {
108:                String name = getRandomString();
109:                String name2 = name + "-2";
110:                cacheMgr.addCache(name, 100);
111:                cacheMgr.addCache(name2, 100);
112:
113:                Set expected = new HashSet();
114:                expected.add(name);
115:                expected.add(name2);
116:
117:                assertEquals("invalid cache names types found", expected,
118:                        cacheMgr.getCacheNames());
119:            }
120:
121:            public void testClearAllCacheEntries() {
122:                String name = getRandomString();
123:                Cache cache = new Cache(name, 5);
124:                CacheEntry entry = new CacheEntry(getRandomString(), "value");
125:                cache.put(entry);
126:                cacheMgr.addCache(cache);
127:
128:                assertEquals("invalid initial cache entry size", 1, cacheMgr
129:                        .getCache(name).getEntries().size());
130:                cacheMgr.clearAllEntries();
131:                assertEquals("invalid cache entry size after clearAll", 0,
132:                        cacheMgr.getCache(name).getEntries().size());
133:            }
134:
135:            public void testGetCaches() {
136:                String name = getRandomString();
137:                Cache cache = new Cache(name, 5);
138:                Cache cache2 = new Cache(name + "2", 5);
139:                cacheMgr.addCache(cache);
140:                cacheMgr.addCache(cache2);
141:
142:                Set expected = new HashSet();
143:                expected.add(cache);
144:                expected.add(cache2);
145:
146:                assertEquals("invalid caches found", expected, cacheMgr
147:                        .getCaches());
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.