Source Code Cross Referenced for DeploymentServiceTest.java in  » Inversion-of-Control » carbon » org » sape » carbon » services » deployment » 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.services.deployment.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.services.deployment.test;
019:
020:        import org.sape.carbon.core.component.Component;
021:        import org.sape.carbon.core.component.Lookup;
022:        import org.sape.carbon.core.component.lifecycle.StateTransitionException;
023:        import org.sape.carbon.core.config.Config;
024:        import org.sape.carbon.core.config.InvalidConfigurationException;
025:        import org.sape.carbon.core.config.PropertyConfiguration;
026:        import org.sape.carbon.core.config.interceptor.ConfigurationInterceptor;
027:        import org.sape.carbon.services.deployment.DeploymentServiceConfiguration;
028:        import org.sape.carbon.services.deployment.namelookup.NameLookup;
029:
030:        import junit.extensions.ActiveTestSuite;
031:        import junit.framework.Test;
032:        import junit.framework.TestCase;
033:        import junit.framework.TestSuite;
034:
035:        /**
036:         * Template for junit test harness.  Change this description to reflect what this class is testing.
037:         * @since carbon 1.0
038:         * @author Douglas Voet, April 2002
039:         * @version $Revision: 1.8 $($Author: dvoet $ / $Date: 2003/09/24 20:31:11 $)
040:         * <br>Copyright 2002 Sapient
041:         */
042:        public class DeploymentServiceTest extends TestCase {
043:            private static final String DEPLOYMENT_COMPONENT_NAME = "/deployment/test/DeploymentService";
044:            private static final String PROD_NAME_LOOKUP = "/deployment/test/ProdLookup";
045:            private static final String DEV_NAME_LOOKUP = "/deployment/test/DevLookup";
046:            private static final String INST_NAME_LOOKUP = "/deployment/test/InstLookup";
047:            public static final String DEV_ENV_NAME = "dev";
048:            public static final String INST_NAME = "inst";
049:            public static final String PROD_ENV_NAME = "prod";
050:            private static final String CURRENT_DEPLOYMENT_NODE = "/deployment/test/deployments/CurrentDeployment";
051:
052:            public DeploymentServiceTest(String name) {
053:                super (name);
054:            }
055:
056:            public void testEnvironmentOnly() {
057:                Component deploymentService = Lookup.getInstance()
058:                        .fetchComponent(DEPLOYMENT_COMPONENT_NAME);
059:
060:                ((DeploymentServiceConfiguration) deploymentService)
061:                        .setEnvironmentName(PROD_ENV_NAME);
062:                ((DeploymentServiceConfiguration) deploymentService)
063:                        .setInstanceName(null);
064:
065:                ((ConfigurationInterceptor) deploymentService)
066:                        .applyConfiguration();
067:
068:                PropertyConfiguration config = (PropertyConfiguration) Config
069:                        .getInstance().fetchConfiguration(
070:                                CURRENT_DEPLOYMENT_NODE);
071:
072:                try {
073:                    TestCase.assertTrue(
074:                            "Unexpected value from config: Expected [prod] found ["
075:                                    + config.getProperty("Prop1") + "]", "prod"
076:                                    .equals(config.getProperty("Prop1")));
077:                    TestCase.assertTrue(
078:                            "Unexpected value from config: Expected [prod] found ["
079:                                    + config.getProperty("Prop2") + "]", "prod"
080:                                    .equals(config.getProperty("Prop2")));
081:                } catch (InvalidConfigurationException ice) {
082:                    TestCase.fail("Property not found: " + ice);
083:                }
084:            }
085:
086:            public void testSeparateInstances() {
087:                Component deploymentService = Lookup.getInstance()
088:                        .fetchComponent(DEPLOYMENT_COMPONENT_NAME);
089:
090:                ((DeploymentServiceConfiguration) deploymentService)
091:                        .setEnvironmentName(DEV_ENV_NAME);
092:                ((DeploymentServiceConfiguration) deploymentService)
093:                        .setInstanceName(INST_NAME);
094:
095:                ((ConfigurationInterceptor) deploymentService)
096:                        .applyConfiguration();
097:
098:                PropertyConfiguration config = (PropertyConfiguration) Config
099:                        .getInstance().fetchConfiguration(
100:                                CURRENT_DEPLOYMENT_NODE);
101:
102:                try {
103:                    TestCase.assertTrue(
104:                            "Unexpected value from config: Expected [dev] found ["
105:                                    + config.getProperty("Prop1") + "]", "dev"
106:                                    .equals(config.getProperty("Prop1")));
107:                    TestCase.assertTrue(
108:                            "Unexpected value from config: Expected [inst] found ["
109:                                    + config.getProperty("Prop2") + "]", "inst"
110:                                    .equals(config.getProperty("Prop2")));
111:                } catch (InvalidConfigurationException ice) {
112:                    TestCase.fail("Property not found: " + ice);
113:                }
114:            }
115:
116:            public void testInvalidConfigurations() {
117:                try {
118:                    Lookup.getInstance().fetchComponent(
119:                            "/deployment/test/InvalidDeploymentService1");
120:                    fail("InvalidDeploymentService1 did not throw expected exception");
121:                } catch (StateTransitionException ste) {
122:                    // expected
123:                }
124:
125:                try {
126:                    Lookup.getInstance().fetchComponent(
127:                            "/deployment/test/InvalidDeploymentService2");
128:                    fail("InvalidDeploymentService2 did not throw expected exception");
129:                } catch (StateTransitionException ste) {
130:                    // expected
131:                }
132:
133:                try {
134:                    Lookup.getInstance().fetchComponent(
135:                            "/deployment/test/InvalidDeploymentService3");
136:                    fail("InvalidDeploymentService3 did not throw expected exception");
137:                } catch (StateTransitionException ste) {
138:                    // expected
139:                }
140:            }
141:
142:            public void testEnvironmentOnlyWithLookup() {
143:                Component deploymentService = Lookup.getInstance()
144:                        .fetchComponent(DEPLOYMENT_COMPONENT_NAME);
145:
146:                ((DeploymentServiceConfiguration) deploymentService)
147:                        .setEnvironmentName(null);
148:                ((DeploymentServiceConfiguration) deploymentService)
149:                        .setInstanceName(null);
150:                ((DeploymentServiceConfiguration) deploymentService)
151:                        .setEnvironmentNameLookup((NameLookup) Lookup
152:                                .getInstance().fetchComponent(PROD_NAME_LOOKUP));
153:
154:                ((ConfigurationInterceptor) deploymentService)
155:                        .applyConfiguration();
156:
157:                PropertyConfiguration config = (PropertyConfiguration) Config
158:                        .getInstance().fetchConfiguration(
159:                                CURRENT_DEPLOYMENT_NODE);
160:
161:                try {
162:                    TestCase.assertTrue(
163:                            "Unexpected value from config: Expected [prod] found ["
164:                                    + config.getProperty("Prop1") + "]", "prod"
165:                                    .equals(config.getProperty("Prop1")));
166:                    TestCase.assertTrue(
167:                            "Unexpected value from config: Expected [prod] found ["
168:                                    + config.getProperty("Prop2") + "]", "prod"
169:                                    .equals(config.getProperty("Prop2")));
170:                } catch (InvalidConfigurationException ice) {
171:                    TestCase.fail("Property not found: " + ice);
172:                }
173:            }
174:
175:            public void testSeparateInstancesWithLookup() {
176:                Component deploymentService = Lookup.getInstance()
177:                        .fetchComponent(DEPLOYMENT_COMPONENT_NAME);
178:
179:                ((DeploymentServiceConfiguration) deploymentService)
180:                        .setEnvironmentName(null);
181:                ((DeploymentServiceConfiguration) deploymentService)
182:                        .setInstanceName(null);
183:                ((DeploymentServiceConfiguration) deploymentService)
184:                        .setEnvironmentNameLookup((NameLookup) Lookup
185:                                .getInstance().fetchComponent(DEV_NAME_LOOKUP));
186:                ((DeploymentServiceConfiguration) deploymentService)
187:                        .setInstanceNameLookup((NameLookup) Lookup
188:                                .getInstance().fetchComponent(INST_NAME_LOOKUP));
189:
190:                ((ConfigurationInterceptor) deploymentService)
191:                        .applyConfiguration();
192:
193:                PropertyConfiguration config = (PropertyConfiguration) Config
194:                        .getInstance().fetchConfiguration(
195:                                CURRENT_DEPLOYMENT_NODE);
196:
197:                try {
198:                    TestCase.assertTrue(
199:                            "Unexpected value from config: Expected [dev] found ["
200:                                    + config.getProperty("Prop1") + "]", "dev"
201:                                    .equals(config.getProperty("Prop1")));
202:                    TestCase.assertTrue(
203:                            "Unexpected value from config: Expected [inst] found ["
204:                                    + config.getProperty("Prop2") + "]", "inst"
205:                                    .equals(config.getProperty("Prop2")));
206:                } catch (InvalidConfigurationException ice) {
207:                    TestCase.fail("Property not found: " + ice);
208:                }
209:            }
210:
211:            /**
212:             * Method called by jUnit to get all the tests in this test case.
213:             * @return Test the suite of tests in this test case
214:             */
215:            public static Test suite() {
216:                TestSuite masterSuite = new TestSuite();
217:                // add single threaded tests
218:                Test singleThreadedTests = getSingleThreadedTests();
219:                if (singleThreadedTests != null) {
220:                    masterSuite.addTest(singleThreadedTests);
221:                }
222:                // add multi threaded tests
223:                Test multiThreadedTests = getMultiThreadedTests();
224:                if (multiThreadedTests != null) {
225:                    masterSuite.addTest(multiThreadedTests);
226:                }
227:                return masterSuite;
228:            }
229:
230:            /**
231:             * This method is used within the suite method to get all of the single threaded tests.
232:             * Add all your single threaded tests in this method with a line like:
233:             * suite.addTest(new DeploymentServiceTest("testFunction1"));
234:             * @return Test the suite of single threaded tests in this test case
235:             */
236:            private static Test getSingleThreadedTests() {
237:                TestSuite suite = new TestSuite();
238:
239:                suite.addTest(new DeploymentServiceTest("testEnvironmentOnly"));
240:                suite
241:                        .addTest(new DeploymentServiceTest(
242:                                "testSeparateInstances"));
243:                suite.addTest(new DeploymentServiceTest(
244:                        "testEnvironmentOnlyWithLookup"));
245:                suite.addTest(new DeploymentServiceTest(
246:                        "testSeparateInstancesWithLookup"));
247:                suite.addTest(new DeploymentServiceTest(
248:                        "testInvalidConfigurations"));
249:
250:                return suite;
251:            }
252:
253:            /**
254:             * This method is used within the suite method to get all of the multi threaded tests.
255:             * Add all your multi threaded tests in this method with a line like: addTest(suite, "testFunction1", 5);
256:             * @return Test the suite of multi-threaded tests in this test case
257:             */
258:            private static Test getMultiThreadedTests() {
259:                TestSuite suite = new ActiveTestSuite();
260:
261:                /*
262:                 * add your tests here following these examples:
263:                 *
264:                 * addTest(suite, "testFunction1", 5);
265:                 * addTest(suite, "testFunction2", 10);
266:                 */
267:
268:                return suite;
269:            }
270:
271:            /**
272:             * This method will add the give test to the give suite the specified
273:             * number of times.  This is best used for multi-threaded tests where
274:             * suite is an instance of ActiveTestSuite and you want to run the same test in multiple threads.
275:             * @param suite the suite to add the test to.
276:             * @param testName the name of the test to add.
277:             * @param number the number of times to add the test to the suite
278:             */
279:            private static void addTest(TestSuite suite, String testName,
280:                    int number) {
281:                for (int count = 0; count < number; count++) {
282:                    suite.addTest(new DeploymentServiceTest(testName));
283:                }
284:            }
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.