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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2005 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 any 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:         * --------------------------------------------------------------------------
022:         * $Id$
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jtests.clients.mbeans;
025:
026:        import java.util.Properties;
027:
028:        import javax.management.ObjectName;
029:        import javax.management.j2ee.Management;
030:        import javax.management.j2ee.ManagementHome;
031:        import javax.naming.InitialContext;
032:        import javax.rmi.PortableRemoteObject;
033:
034:        import junit.framework.Test;
035:        import junit.framework.TestSuite;
036:
037:        import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
038:
039:        /**
040:         * Test WebServices MBeans (WebServices, Service, PortComponent and Handler).
041:         *
042:         * @author Guillaume Sauthier
043:         */
044:        public class F_WebServicesMBeans extends JWebServicesTestCase {
045:
046:            /**
047:             * MEJB instance
048:             */
049:            private Management mejb = null;
050:
051:            /**
052:             * Service of Time Sample's ObjectName
053:             */
054:            private static final String SERVICE_MBEAN_ON = "jonas:type=WebService,name=TimeWebService,J2EEServer=jonas,J2EEApplication=time-test,EJBModule=time";
055:
056:            /**
057:             * PortComponent of Time Sample's ObjectName
058:             */
059:            private static final String PC_MBEAN_ON = "jonas:type=WebServicePortComponent,name=TimePort,WebService=TimeWebService,J2EEServer=jonas,EJBModule=time,J2EEApplication=time-test";
060:
061:            /**
062:             * Handler of Time Sample's ObjectName
063:             */
064:            private static final String HANDLER_MBEAN_ON = "jonas:type=WebServiceHandler,name=TimeBeanHandler,WebServicePortComponent=TimePort,EJBModule=time,J2EEServer=jonas,J2EEApplication=time-test,WebService=TimeWebService";
065:
066:            /**
067:             * SessionBean realizing the Time Service
068:             */
069:            private static final String SSB_MBEAN_ON = "jonas:j2eeType=StatelessSessionBean,name=TimeBeanSLR,EJBModule=time,J2EEApplication=time-test,J2EEServer=jonas";
070:
071:            // =================== Attributes pre-filling ======================================
072:
073:            /**
074:             * Service.portComponents
075:             */
076:            private static final String[] SERVICE_PCS_ATT = new String[] { PC_MBEAN_ON };
077:
078:            /**
079:             * PortComponent.handlers
080:             */
081:            private static final String[] PC_HANDLERS_ATT = new String[] { HANDLER_MBEAN_ON };
082:
083:            /**
084:             * Handler.soapHeaders
085:             */
086:            private static final String[] SOAP_HEADERS = new String[] {};
087:
088:            /**
089:             * Handler.soapRoles
090:             */
091:            private static final String[] SOAP_ROLES = new String[] {};
092:
093:            /**
094:             * Handler.initParams
095:             */
096:            private static Properties INIT_PARAMS = null;
097:
098:            /**
099:             * Inner static class used to store tests expected results
100:             *
101:             * @author Guillaume Sauthier
102:             */
103:            private static class WsTest {
104:                /**
105:                 * MBean attribute name
106:                 */
107:                public String name;
108:
109:                /**
110:                 * MBean attribute type
111:                 */
112:                public Class type;
113:
114:                /**
115:                 * Expected result
116:                 */
117:                public Object expected;
118:
119:                /**
120:                 * does the String represents an ObjectName ?
121:                 */
122:                public boolean isObjectName;
123:
124:                /**
125:                 * WsTest Constructor
126:                 * @param name att name
127:                 * @param type att type
128:                 * @param expected att value
129:                 */
130:                public WsTest(String name, Class type, Object expected) {
131:                    this (name, type, expected, false);
132:                }
133:
134:                /**
135:                 * WsTest Constructor
136:                 * @param name att name
137:                 * @param type att type
138:                 * @param expected att value
139:                 */
140:                public WsTest(String name, Class type, Object expected,
141:                        boolean on) {
142:                    super ();
143:                    this .name = name;
144:                    this .type = type;
145:                    this .expected = expected;
146:                    this .isObjectName = on;
147:                }
148:            }
149:
150:            /**
151:             * Tests values for Service MBean
152:             */
153:            private WsTest[] SERVICE_TEST = null;
154:
155:            /**
156:             * Tests values for PortComponent MBean
157:             */
158:            private WsTest[] PORT_TEST = null;
159:
160:            /**
161:             * Tests values for Handler MBean
162:             */
163:            private WsTest[] HANDLER_TEST = null;
164:
165:            /**
166:             * Are the tables init ?
167:             */
168:            private boolean initialized = false;
169:
170:            public F_WebServicesMBeans(String s) {
171:                super (s);
172:            }
173:
174:            public static Test suite() {
175:                return new TestSuite(F_WebServicesMBeans.class);
176:            }
177:
178:            public void setUp() throws Exception {
179:                super .setUp();
180:                useEar("time-test");
181:                mejb = getMEJB();
182:                if (!initialized) {
183:                    initTestsTables();
184:                    initialized = true;
185:                }
186:            }
187:
188:            /**
189:             * init tables
190:             */
191:            private void initTestsTables() {
192:
193:                INIT_PARAMS = new Properties();
194:                INIT_PARAMS.put("jonas.test.server.handler", "JOnAS");
195:
196:                SERVICE_TEST = new WsTest[] {
197:                        new WsTest("name", java.lang.String.class,
198:                                "TimeWebService"),
199:                        new WsTest("portComponents", java.lang.String[].class,
200:                                SERVICE_PCS_ATT, true),
201:                        new WsTest("wsdlURL", java.lang.String.class,
202:                                getAbsoluteUrl("/time/TimePort/TimePort?JWSDL")),
203:                        new WsTest("mappingFilename", java.lang.String.class,
204:                                "META-INF/mapping.xml"),
205:                        new WsTest("wsdlFilename", java.lang.String.class,
206:                                "META-INF/wsdl/TimePort.wsdl") };
207:
208:                PORT_TEST = new WsTest[] {
209:                        new WsTest("name", java.lang.String.class, "TimePort"),
210:                        new WsTest("handlers", java.lang.String[].class,
211:                                PC_HANDLERS_ATT, true),
212:                        new WsTest("wsdlPort", java.lang.String.class,
213:                                "{jonas:Time}TimePort"),
214:                        new WsTest("serviceEndpointInterface",
215:                                java.lang.String.class,
216:                                "org.objectweb.jonas.jtests.beans.time.TimeEndpoint"),
217:                        new WsTest("endpoint", java.lang.String.class,
218:                                getAbsoluteUrl("/time/TimePort/TimePort")),
219:                        new WsTest("implementationBean",
220:                                java.lang.String.class, SSB_MBEAN_ON, true) };
221:
222:                HANDLER_TEST = new WsTest[] {
223:                        new WsTest("name", java.lang.String.class,
224:                                "TimeBeanHandler"),
225:                        new WsTest("classname", java.lang.String.class,
226:                                "org.objectweb.jonas.jtests.beans.time.TimeBeanHandler"),
227:                        new WsTest("soapHeaders", java.lang.String[].class,
228:                                SOAP_HEADERS),
229:                        new WsTest("soapRoles", java.lang.String[].class,
230:                                SOAP_ROLES),
231:                        new WsTest("initParams", java.util.Properties.class,
232:                                INIT_PARAMS) };
233:
234:            }
235:
236:            private Management getMEJB() throws Exception {
237:                InitialContext ic = new InitialContext();
238:                Object o = ic.lookup("ejb/mgmt/MEJB");
239:                ManagementHome home = (ManagementHome) PortableRemoteObject
240:                        .narrow(o, ManagementHome.class);
241:                return home.create();
242:            }
243:
244:            public void tearDown() throws Exception {
245:                super .tearDown();
246:                mejb = null;
247:            }
248:
249:            public void testWebServiceMBean() throws Exception {
250:                checkMBean(SERVICE_MBEAN_ON, SERVICE_TEST);
251:            }
252:
253:            public void testPortComponentMBean() throws Exception {
254:                checkMBean(PC_MBEAN_ON, PORT_TEST);
255:                // check that the implementationBean is live
256:                String se = (String) mejb.getAttribute(new ObjectName(
257:                        PC_MBEAN_ON), "implementationBean");
258:                assertTrue("implementationBean MBean must be registered", mejb
259:                        .isRegistered(new ObjectName(se)));
260:            }
261:
262:            public void testHandlerMBean() throws Exception {
263:                checkMBean(HANDLER_MBEAN_ON, HANDLER_TEST);
264:            }
265:
266:            private void checkMBean(String onStr, WsTest[] tests)
267:                    throws Exception {
268:                ObjectName on = ObjectName.getInstance(onStr);
269:                assertTrue("ObjectName not registered " + on, mejb
270:                        .isRegistered(on));
271:
272:                for (int i = 0; i < tests.length; i++) {
273:
274:                    boolean isObjectName = tests[i].isObjectName;
275:
276:                    Object o = mejb.getAttribute(on, tests[i].name);
277:                    assertNotNull("Cannot retrieve attribute '" + tests[i].name
278:                            + "' from " + on, o);
279:                    assertEquals("Expecting type " + tests[i].type
280:                            + " for attribute " + tests[i].name, tests[i].type,
281:                            o.getClass());
282:                    if (tests[i].type.isArray()) {
283:                        Object[] a1 = (Object[]) o;
284:                        Object[] a2 = (Object[]) tests[i].expected;
285:                        assertEquals(
286:                                "'" + tests[i].name + "' Array size error",
287:                                a2.length, a1.length);
288:
289:                        for (int j = 0; j < a1.length; j++) {
290:                            if (isObjectName) {
291:                                assertEquals("'" + tests[i].name + "[" + j
292:                                        + "]'  mismatch", new ObjectName(
293:                                        (String) a2[j]), new ObjectName(
294:                                        (String) a1[j]));
295:                            } else {
296:                                assertEquals("'" + tests[i].name + "[" + j
297:                                        + "]'  mismatch", a2[j], a1[j]);
298:                            }
299:                        }
300:                    } else {
301:                        if (isObjectName) {
302:                            assertEquals("'" + tests[i].name + "' mismatch",
303:                                    new ObjectName((String) tests[i].expected),
304:                                    new ObjectName((String) o));
305:                        } else {
306:                            assertEquals("'" + tests[i].name + "' mismatch",
307:                                    tests[i].expected, o);
308:                        }
309:                    }
310:                }
311:            }
312:
313:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.