Source Code Cross Referenced for ConfigurationCacheTest.java in  » Inversion-of-Control » carbon » org » sape » carbon » core » config » cache » test » 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 » Inversion of Control » carbon » org.sape.carbon.core.config.cache.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Sapient Public License
003:         * Version 1.0 (the "License"); you may not use this file except in compliance
004:         * with the License. You may obtain a copy of the License at
005:         * http://carbon.sf.net/License.html.
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is The Carbon Component Framework.
012:         *
013:         * The Initial Developer of the Original Code is Sapient Corporation
014:         *
015:         * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016:         */
017:
018:        package org.sape.carbon.core.config.cache.test;
019:
020:        import org.sape.carbon.core.bootstrap.BootStrapper;
021:        import org.sape.carbon.core.config.Config;
022:        import org.sape.carbon.core.config.ConfigurationException;
023:        import org.sape.carbon.core.config.ConfigurationNotFoundException;
024:        import org.sape.carbon.core.config.PropertyConfiguration;
025:        import org.sape.carbon.core.config.cache.ConfigurationCache;
026:        import org.sape.carbon.core.config.cache.ConfigurationCacheFactory;
027:        import org.sape.carbon.core.config.cache.DoubleCheckConfigurationCache;
028:        import org.sape.carbon.core.config.cache.SynchronizedConfigurationCache;
029:
030:        import junit.extensions.ActiveTestSuite;
031:        import junit.framework.Test;
032:        import junit.framework.TestCase;
033:        import junit.framework.TestSuite;
034:
035:        /**
036:         *
037:         *
038:         * Copyright 2002 Sapient
039:         * @since carbon 1.1
040:         * @author Douglas Voet, Oct 25, 2002
041:         * @version $Revision: 1.4 $($Author: dvoet $ / $Date: 2003/05/05 21:21:16 $)
042:         */
043:        public class ConfigurationCacheTest extends TestCase {
044:
045:            private String actualCacheClassName;
046:
047:            public ConfigurationCacheTest(String name) {
048:                super (name);
049:            }
050:
051:            public void testSynchronizedCache() throws ConfigurationException {
052:                setCacheClass(SynchronizedConfigurationCache.class);
053:                testCache();
054:                restoreCacheClass();
055:            }
056:
057:            public void testDoubleCheckCache() throws ConfigurationException {
058:                setCacheClass(DoubleCheckConfigurationCache.class);
059:                testCache();
060:                restoreCacheClass();
061:            }
062:
063:            private void setCacheClass(Class cacheClass) {
064:                this .actualCacheClassName = BootStrapper
065:                        .getInstance()
066:                        .getDeploymentProperty(
067:                                ConfigurationCacheFactory.CACHE_TYPE_PROPERTY_NAME);
068:
069:                BootStrapper.getInstance().setDeploymentProperty(
070:                        ConfigurationCacheFactory.CACHE_TYPE_PROPERTY_NAME,
071:                        cacheClass.getName());
072:            }
073:
074:            private void restoreCacheClass() {
075:                BootStrapper.getInstance().setDeploymentProperty(
076:                        ConfigurationCacheFactory.CACHE_TYPE_PROPERTY_NAME,
077:                        this .actualCacheClassName);
078:            }
079:
080:            private void testCache() throws ConfigurationException {
081:                final String CONFIG_NAME = "/core/test/ConfigurationCacheTest";
082:                final String ATTRIBUTE_NAME = "foo";
083:
084:                PropertyConfiguration origConfig = (PropertyConfiguration) Config
085:                        .getInstance().createConfiguration(
086:                                PropertyConfiguration.class);
087:
088:                origConfig.setProperty(ATTRIBUTE_NAME, "bar");
089:                Config.getInstance()
090:                        .storeConfiguration(CONFIG_NAME, origConfig);
091:
092:                ConfigurationCache cache = ConfigurationCacheFactory
093:                        .getInstance(Config.getInstance()
094:                                .getConfigurationService());
095:
096:                PropertyConfiguration cachedConfig = (PropertyConfiguration) cache
097:                        .getConfiguration(CONFIG_NAME);
098:
099:                origConfig.setProperty(ATTRIBUTE_NAME, "splat");
100:                Config.getInstance()
101:                        .storeConfiguration(CONFIG_NAME, origConfig);
102:
103:                PropertyConfiguration changedConfig = (PropertyConfiguration) cache
104:                        .getConfiguration(CONFIG_NAME);
105:
106:                TestCase.assertTrue("Cached configuration did not change",
107:                        !cachedConfig.getProperty(ATTRIBUTE_NAME).equals(
108:                                changedConfig.getProperty(ATTRIBUTE_NAME)));
109:
110:                Config.getInstance().fetchNode(CONFIG_NAME).remove();
111:
112:                try {
113:                    cache.getConfiguration(CONFIG_NAME);
114:                    TestCase.fail("Cached configuration was not removed");
115:                } catch (ConfigurationNotFoundException cnfe) {
116:                    // expected
117:                }
118:            }
119:
120:            /**
121:             * Method called by jUnit to get all the tests in this test case.
122:             * @return Test the suite of tests in this test case
123:             */
124:            public static Test suite() {
125:                TestSuite masterSuite = new TestSuite();
126:                // add single threaded tests
127:                Test singleThreadedTests = getSingleThreadedTests();
128:                if (singleThreadedTests != null) {
129:                    masterSuite.addTest(singleThreadedTests);
130:                }
131:                // add multi threaded tests
132:                Test multiThreadedTests = getMultiThreadedTests();
133:                if (multiThreadedTests != null) {
134:                    masterSuite.addTest(multiThreadedTests);
135:                }
136:                return masterSuite;
137:            }
138:
139:            /**
140:             * This method is used within the suite method to get all of the single threaded tests.
141:             * Add all your single threaded tests in this method with a line like:
142:             * suite.addTest(new InternalNodeTest("testFunction1"));
143:             * @return Test the suite of single threaded tests in this test case
144:             */
145:            private static Test getSingleThreadedTests() {
146:                TestSuite suite = new TestSuite();
147:
148:                suite.addTest(new ConfigurationCacheTest(
149:                        "testSynchronizedCache"));
150:                suite
151:                        .addTest(new ConfigurationCacheTest(
152:                                "testDoubleCheckCache"));
153:
154:                return suite;
155:            }
156:
157:            /**
158:             * This method is used within the suite method to get all of the multi threaded tests.
159:             * Add all your multi threaded tests in this method with a line like: addTest(suite, "testFunction1", 5);
160:             * @return Test the suite of multi-threaded tests in this test case
161:             */
162:            private static Test getMultiThreadedTests() {
163:                TestSuite suite = new ActiveTestSuite();
164:
165:                /*
166:                 * add your tests here following these examples:
167:                 *
168:                 * addTest(suite, "testFunction1", 5);
169:                 * addTest(suite, "testFunction2", 10);
170:                 */
171:
172:                return suite;
173:            }
174:
175:            /**
176:             * This method will add the give test to the give suite the specified
177:             * number of times.  This is best used for multi-threaded tests where
178:             * suite is an instance of ActiveTestSuite and you want to run the same test in multiple threads.
179:             * @param suite the suite to add the test to.
180:             * @param testName the name of the test to add.
181:             * @param number the number of times to add the test to the suite
182:             */
183:            private static void addTest(TestSuite suite, String testName,
184:                    int number) {
185:                for (int count = 0; count < number; count++) {
186:                    suite.addTest(new ConfigurationCacheTest(testName));
187:                }
188:            }
189:        }
ww___w_.__j_ava_2s._co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.