Source Code Cross Referenced for JWebServicesTestCase.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » util » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jtests.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or 1any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer: Florent BENOIT
022:         * --------------------------------------------------------------------------
023:         * $Id: JWebServicesTestCase.java 7516 2005-10-18 07:09:43Z sauthieg $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas.jtests.util;
026:
027:        import java.io.File;
028:
029:        import javax.naming.Context;
030:        import javax.naming.InitialContext;
031:        import javax.naming.NamingException;
032:        import javax.rmi.PortableRemoteObject;
033:
034:        import junit.framework.TestCase;
035:
036:        import org.objectweb.jonas.adm.AdmInterface;
037:
038:        import com.meterware.httpunit.WebConversation;
039:
040:        /**
041:         * Define a class to add useful methods for test the webservices
042:         *  - Deploy ear, war and beans
043:         *  - Retrieve initial context
044:         * @author Florent Benoit
045:         */
046:        public class JWebServicesTestCase extends TestCase {
047:
048:            /**
049:             * Name of the JOnAS server used for tests
050:             */
051:            private static String jonasName = "jonas";
052:
053:            /**
054:             * Initial context used for lookup
055:             */
056:            protected static Context ictx = null;
057:
058:            /**
059:             * JOnAS admin used for communicate via JMX to JOnAS
060:             */
061:            private static AdmInterface admI = null;
062:
063:            /**
064:             * Conversation used for HttpUnit
065:             */
066:            protected WebConversation wc = null;
067:
068:            /**
069:             * URL used for the constructor
070:             */
071:            protected String url = null;
072:
073:            /**
074:             * Prefix for build URLs
075:             */
076:            private String prefixUrl = null;
077:
078:            /**
079:             * Add to the specified url the prefix
080:             * @param url relative URL
081:             * @return absolute path of URL
082:             */
083:            protected String getAbsoluteUrl(String url) {
084:                return (this .prefixUrl + url);
085:            }
086:
087:            /**
088:             * Initialize the port used by tests and the prefix
089:             */
090:            private void init() {
091:                String port = System.getProperty("http.port");
092:                if (port == null) {
093:                    port = "9000";
094:                }
095:
096:                prefixUrl = "http://localhost:" + port;
097:            }
098:
099:            /**
100:             * Constructor with a specified name
101:             * @param s the name
102:             */
103:            public JWebServicesTestCase(String s) {
104:                super (s);
105:                init();
106:            }
107:
108:            /**
109:             * Constructor with a specified name and url
110:             * @param s the name
111:             * @param url the url which can be used
112:             */
113:            public JWebServicesTestCase(String s, String url) {
114:                super (s);
115:                wc = new WebConversation();
116:                init();
117:                this .url = getAbsoluteUrl(url);
118:            }
119:
120:            /**
121:             * Get initialContext
122:             * @return the initialContext
123:             * @throws NamingException if the initial context can't be retrieved
124:             */
125:            private Context getInitialContext() throws NamingException {
126:                return new InitialContext();
127:            }
128:
129:            /**
130:             * Common setUp routine, used for every test.
131:             * @throws Exception if an error occurs
132:             */
133:            protected void setUp() throws Exception {
134:                try {
135:                    // get InitialContext
136:                    if (ictx == null) {
137:                        ictx = getInitialContext();
138:                    }
139:                    if (admI == null) {
140:                        admI = (AdmInterface) PortableRemoteObject
141:                                .narrow(ictx.lookup(jonasName + "_Adm"),
142:                                        AdmInterface.class);
143:                    }
144:
145:                } catch (NamingException e) {
146:                    System.err.println("Cannot setup test: " + e);
147:                    e.printStackTrace();
148:                }
149:            }
150:
151:            /**
152:             * Load an ear file in the jonas server
153:             * @param filename ear file, without ".ear" extension
154:             * @throws Exception if an error occurs
155:             */
156:            public void useEar(String filename) throws Exception {
157:
158:                try {
159:                    // Load ear in JOnAS if not already loaded.
160:                    if (ictx == null) {
161:                        ictx = getInitialContext();
162:                    }
163:
164:                    if (admI == null) {
165:                        admI = (AdmInterface) PortableRemoteObject
166:                                .narrow(ictx.lookup(jonasName + "_Adm"),
167:                                        AdmInterface.class);
168:                    }
169:
170:                    //Test in both directories (apps/ and apps/autoload)
171:                    String appsFileName = filename + ".ear";
172:                    String autoloadAppsFileName = "autoload" + File.separator
173:                            + filename + ".ear";
174:                    if (!admI.isEarLoaded(appsFileName)
175:                            && !admI.isEarLoaded(autoloadAppsFileName)) {
176:                        //if the file was in autoload, it was loaded
177:                        admI.addEar(appsFileName);
178:                    }
179:
180:                } catch (Exception e) {
181:                    throw new Exception("Cannot load Ear : " + e.getMessage());
182:                }
183:            }
184:
185:            /**
186:             * Load a war file in the jonas server
187:             * @param filename war file, without ".war" extension
188:             * @throws Exception if an error occurs
189:             */
190:            public void useWar(String filename) throws Exception {
191:
192:                try {
193:                    // Load war in JOnAS if not already loaded.
194:                    if (ictx == null) {
195:                        ictx = getInitialContext();
196:                    }
197:
198:                    if (admI == null) {
199:                        admI = (AdmInterface) PortableRemoteObject
200:                                .narrow(ictx.lookup(jonasName + "_Adm"),
201:                                        AdmInterface.class);
202:                    }
203:
204:                    //Test in both directories (apps/ and apps/autoload)
205:                    String webappsFileName = filename + ".war";
206:                    String autoloadWebappsFileName = "autoload"
207:                            + File.separator + filename + ".war";
208:                    if (!admI.isWarLoaded(webappsFileName)
209:                            && !admI.isWarLoaded(autoloadWebappsFileName)) {
210:                        //if the file was in autoload, it was loaded
211:                        admI.addWar(webappsFileName);
212:                    }
213:
214:                } catch (Exception e) {
215:                    throw new Exception("Cannot load War : " + e.getMessage());
216:                }
217:            }
218:
219:            /**
220:             * Load a bean jar file in the jonas server
221:             * @param filename jar file, without ".jar" extension
222:             * @throws Exception if an error occurs
223:             */
224:            public void useBeans(String filename) throws Exception {
225:                try {
226:                    // Load bean in EJBServer if not already loaded.
227:                    if (ictx == null) {
228:                        ictx = getInitialContext();
229:                    }
230:                    if (admI == null) {
231:                        admI = (AdmInterface) PortableRemoteObject
232:                                .narrow(ictx.lookup(jonasName + "_Adm"),
233:                                        AdmInterface.class);
234:                    }
235:                    if (!admI.isLoaded(filename + ".jar")) {
236:                        admI.addBeans(filename + ".jar");
237:                    }
238:                } catch (Exception e) {
239:                    throw new Exception("Cannot load Bean : " + e.getMessage());
240:                }
241:            }
242:
243:            /**
244:             * Unload a bean jar file in the jonas server
245:             * @param filename jar file, without ".jar" extension
246:             * @throws Exception if an error occurs
247:             */
248:            public void unUseBeans(String filename) throws Exception {
249:                try {
250:                    // Load bean in EJBServer if not already loaded.
251:                    if (ictx == null) {
252:                        ictx = getInitialContext();
253:                    }
254:                    if (admI == null) {
255:                        admI = (AdmInterface) PortableRemoteObject
256:                                .narrow(ictx.lookup(jonasName + "_Adm"),
257:                                        AdmInterface.class);
258:                    }
259:                    if (admI.isLoaded(filename + ".jar")) {
260:                        admI.removeBeans(filename + ".jar");
261:                    }
262:                } catch (Exception e) {
263:                    throw new Exception("Cannot unload Bean : ", e);
264:                }
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.