Source Code Cross Referenced for TestMessageBuilder.java in  » ESB » open-esb » com » sun » jbi » management » message » 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 » ESB » open esb » com.sun.jbi.management.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestMessageBuilder.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.management.message;
030:
031:        import com.sun.jbi.management.ComponentMessageHolder;
032:        import com.sun.jbi.management.system.ScaffoldEnvironmentContext;
033:        import com.sun.jbi.management.system.ManagementException;
034:
035:        import java.util.List;
036:
037:        import javax.xml.bind.JAXBContext;
038:        import javax.xml.bind.Unmarshaller;
039:        import javax.xml.transform.stream.StreamSource;
040:
041:        public class TestMessageBuilder extends junit.framework.TestCase {
042:
043:            private static final String RESPONSE_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
044:                    + "<jbi-task xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\" "
045:                    + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\" "
046:                    + "xsi:schemaLocation=\"http://java.sun.com/xml/ns/jbi/management-message ./managementMessage.xsd\"> "
047:                    + "<jbi-task-result>"
048:                    + "<frmwk-task-result>"
049:                    + "<frmwk-task-result-details>"
050:                    + "<task-result-details>"
051:                    + "<task-id>deploy</task-id>"
052:                    + "<task-result>SUCCESS</task-result>"
053:                    + "<message-type>INFO</message-type>"
054:                    + "<task-status-msg>"
055:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service assembly esbadmin00089-sa succeeded.</loc-message></msg-loc-info>"
056:                    + "</task-status-msg>"
057:                    + "</task-result-details>"
058:                    + "<locale>en_US</locale>"
059:                    + "</frmwk-task-result-details>"
060:                    + "</frmwk-task-result>"
061:                    + "<component-task-result>"
062:                    + "<component-name>manage-binding-1</component-name>"
063:                    + "<component-task-result-details>"
064:                    + "<task-result-details><task-id>deploy</task-id><task-result>SUCCESS</task-result></task-result-details>"
065:                    + "</component-task-result-details>"
066:                    + "</component-task-result>"
067:                    + "<component-task-result>"
068:                    + "<component-name>manage-binding-2</component-name>"
069:                    + "<component-task-result-details>"
070:                    + "<task-result-details><task-id>deploy</task-id><task-result>SUCCESS</task-result></task-result-details>"
071:                    + "</component-task-result-details>"
072:                    + "</component-task-result>"
073:                    + "</jbi-task-result></jbi-task>";
074:
075:            private static final String SAME_COMPONENT_RESPONSE_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
076:                    + "<jbi-task xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\" "
077:                    + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\" "
078:                    + "xsi:schemaLocation=\"http://java.sun.com/xml/ns/jbi/management-message ./managementMessage.xsd\"> "
079:                    + "<jbi-task-result>"
080:                    + "<frmwk-task-result>"
081:                    + "<frmwk-task-result-details>"
082:                    + "<task-result-details>"
083:                    + "<task-id>deploy</task-id>"
084:                    + "<task-result>SUCCESS</task-result>"
085:                    + "<message-type>INFO</message-type>"
086:                    + "<task-status-msg>"
087:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service assembly esbadmin00089-sa succeeded.</loc-message></msg-loc-info>"
088:                    + "</task-status-msg>"
089:                    + "</task-result-details>"
090:                    + "<locale>en_US</locale>"
091:                    + "</frmwk-task-result-details>"
092:                    + "</frmwk-task-result>"
093:                    + "<component-task-result>"
094:                    + "<component-name>manage-binding-1</component-name>"
095:                    + "<component-task-result-details>"
096:                    + "<task-result-details>"
097:                    + "<task-id>deploy</task-id>"
098:                    + "<task-result>SUCCESS</task-result>"
099:                    + "<message-type>INFO</message-type>"
100:                    + "<task-status-msg>"
101:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service unit su11 succeeded.</loc-message></msg-loc-info>"
102:                    + "</task-status-msg>"
103:                    + "</task-result-details>"
104:                    + "</component-task-result-details>"
105:                    + "</component-task-result>"
106:                    + "<component-task-result>"
107:                    + "<component-name>manage-binding-1</component-name>"
108:                    + "<component-task-result-details>"
109:                    + "<task-result-details>"
110:                    + "<task-id>deploy</task-id>"
111:                    + "<task-result>SUCCESS</task-result>"
112:                    + "<message-type>INFO</message-type>"
113:                    + "<task-status-msg>"
114:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service unit su12 succeeded.</loc-message></msg-loc-info>"
115:                    + "</task-status-msg>"
116:                    + "</task-result-details>"
117:                    + "</component-task-result-details>"
118:                    + "</component-task-result>"
119:                    + "</jbi-task-result></jbi-task>";
120:
121:            private static final String SAME_COMPONENT_RESPONSE_2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
122:                    + "<jbi-task xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\" "
123:                    + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\" "
124:                    + "xsi:schemaLocation=\"http://java.sun.com/xml/ns/jbi/management-message ./managementMessage.xsd\"> "
125:                    + "<jbi-task-result>"
126:                    + "<frmwk-task-result>"
127:                    + "<frmwk-task-result-details>"
128:                    + "<task-result-details>"
129:                    + "<task-id>deploy</task-id>"
130:                    + "<task-result>SUCCESS</task-result>"
131:                    + "<message-type>INFO</message-type>"
132:                    + "<task-status-msg>"
133:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service assembly esbadmin00089-sa succeeded.</loc-message></msg-loc-info>"
134:                    + "</task-status-msg>"
135:                    + "</task-result-details>"
136:                    + "<locale>en_US</locale>"
137:                    + "</frmwk-task-result-details>"
138:                    + "</frmwk-task-result>"
139:                    + "<component-task-result>"
140:                    + "<component-name>manage-binding-1</component-name>"
141:                    + "<component-task-result-details>"
142:                    + "<task-result-details>"
143:                    + "<task-id>deploy</task-id>"
144:                    + "<task-result>SUCCESS</task-result>"
145:                    + "<message-type>INFO</message-type>"
146:                    + "<task-status-msg>"
147:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service unit su1 succeeded.</loc-message></msg-loc-info>"
148:                    + "</task-status-msg>"
149:                    + "</task-result-details>"
150:                    + "</component-task-result-details>"
151:                    + "</component-task-result>"
152:                    + "<component-task-result>"
153:                    + "<component-name>manage-binding-1</component-name>"
154:                    + "<component-task-result-details>"
155:                    + "<task-result-details>"
156:                    + "<task-id>deploy</task-id>"
157:                    + "<task-result>SUCCESS</task-result>"
158:                    + "<message-type>INFO</message-type>"
159:                    + "<task-status-msg>"
160:                    + "<msg-loc-info><loc-token>JBIMA0495</loc-token><loc-message>Deployment of service unit su2 succeeded.</loc-message></msg-loc-info>"
161:                    + "</task-status-msg>"
162:                    + "</task-result-details>"
163:                    + "</component-task-result-details>"
164:                    + "</component-task-result>"
165:                    + "</jbi-task-result></jbi-task>";
166:
167:            private static final String EXCEPTION_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><jbi-task version=\"1.0\" "
168:                    + "xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
169:                    + "<jbi-task-result>"
170:                    + "<frmwk-task-result>"
171:                    + "<frmwk-task-result-details>"
172:                    + "<task-result-details>"
173:                    + "<task-id>deploy</task-id>"
174:                    + "<task-result>FAILED</task-result>"
175:                    + "<message-type>ERROR</message-type>"
176:                    + "<task-status-msg>"
177:                    + "<msg-loc-info>"
178:                    + "<loc-token>JBIMA0000</loc-token>"
179:                    + "<loc-message>java.io.FileNotFoundException: /export2/nikita/jbi/main/open-esb/install/as8/nodeagents/agent1/cluster1-instance2/jbi/service-assemblies/esbadmin00089-sa/deploy-sa.jar (Permission denied)</loc-message>"
180:                    + "</msg-loc-info>"
181:                    + "</task-status-msg>"
182:                    + "<exception-info>"
183:                    + "<nesting-level>1</nesting-level>"
184:                    + "<msg-loc-info>"
185:                    + "<loc-token>JBIMA0000</loc-token>"
186:                    + "<loc-message>java.io.FileNotFoundException: /export2/nikita/jbi/main/open-esb/install/as8/nodeagents/agent1/cluster1-instance2/jbi/service-assemblies/esbadmin00089-sa/deploy-sa.jar (Permission denied)</loc-message>"
187:                    + "</msg-loc-info>"
188:                    + "<stack-trace>com.sun.jbi.management.repository.Repository.addToRepository(Repository.java:419)"
189:                    + "com.sun.jbi.management.repository.Repository.addArchive(Repository.java:167)"
190:                    + "com.sun.jbi.management.system.DeploymentService.deploy(DeploymentService.java:219)"
191:                    + "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
192:                    + "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)"
193:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
194:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
195:                    + "com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(StandardMetaDataImpl.java:414)"
196:                    + "javax.management.StandardMBean.invoke(StandardMBean.java:323)"
197:                    + "com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)"
198:                    + "com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)"
199:                    + "com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)"
200:                    + "com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)"
201:                    + "sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)"
202:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
203:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
204:                    + "com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:77)"
205:                    + "$Proxy1.invoke(Unknown Source)"
206:                    + "com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:297)"
207:                    + "javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1408)"
208:                    + "javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:81)"
209:                    + "javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1245)"
210:                    + "javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1341)"
211:                    + "javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:782)"
212:                    + "sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)"
213:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
214:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
215:                    + "sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)"
216:                    + "sun.rmi.transport.Transport$1.run(Transport.java:153)"
217:                    + "java.security.AccessController.doPrivileged(Native Method)"
218:                    + "sun.rmi.transport.Transport.serviceCall(Transport.java:149)"
219:                    + "sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)"
220:                    + "sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)"
221:                    + "java.lang.Thread.run(Thread.java:595)"
222:                    + "</stack-trace></exception-info><exception-info><nesting-level>2</nesting-level><msg-loc-info><loc-token>JBIMA0000</loc-token><loc-message>/export2/nikita/jbi/main/open-esb/install/as8/nodeagents/agent1/cluster1-instance2/jbi/service-assemblies/esbadmin00089-sa/deploy-sa.jar (Permission denied)</loc-message></msg-loc-info><stack-trace>java.io.FileOutputStream.open(Native Method)"
223:                    + "java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:179)"
224:                    + "java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:131)"
225:                    + "com.sun.jbi.management.repository.Repository.addToRepository(Repository.java:402)"
226:                    + "com.sun.jbi.management.repository.Repository.addArchive(Repository.java:167)"
227:                    + "com.sun.jbi.management.system.DeploymentService.deploy(DeploymentService.java:219)"
228:                    + "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
229:                    + "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)"
230:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
231:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
232:                    + "com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(StandardMetaDataImpl.java:414)"
233:                    + "javax.management.StandardMBean.invoke(StandardMBean.java:323)"
234:                    + "com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)"
235:                    + "com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)"
236:                    + "com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)"
237:                    + "com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)"
238:                    + "sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)"
239:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
240:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
241:                    + "com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:77)"
242:                    + "$Proxy1.invoke(Unknown Source)"
243:                    + "com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:297)"
244:                    + "javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1408)"
245:                    + "javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:81)"
246:                    + "javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1245)"
247:                    + "javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1341)"
248:                    + "javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:782)"
249:                    + "sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)"
250:                    + "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)"
251:                    + "java.lang.reflect.Method.invoke(Method.java:585)"
252:                    + "sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)"
253:                    + "sun.rmi.transport.Transport$1.run(Transport.java:153)"
254:                    + "java.security.AccessController.doPrivileged(Native Method)"
255:                    + "sun.rmi.transport.Transport.serviceCall(Transport.java:149)"
256:                    + "sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)"
257:                    + "sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)"
258:                    + "java.lang.Thread.run(Thread.java:595)"
259:                    + "</stack-trace>"
260:                    + "</exception-info>"
261:                    + "</task-result-details>"
262:                    + "<locale>en_US</locale>"
263:                    + "</frmwk-task-result-details></frmwk-task-result>"
264:                    + "</jbi-task-result></jbi-task>";
265:
266:            private ScaffoldEnvironmentContext mEnvCtx;
267:            private JAXBContext mJaxbContext;
268:
269:            public TestMessageBuilder(String aTestName) {
270:                super (aTestName);
271:                mEnvCtx = new ScaffoldEnvironmentContext();
272:
273:            }
274:
275:            public void setUp() throws Exception {
276:                super .setUp();
277:            }
278:
279:            public void tearDown() throws Exception {
280:            }
281:
282:            /**
283:             * @throws Exception if an unexpected error occurs
284:             */
285:            public void testBuildExceptionMessage() throws Exception {
286:                MessageBuilder msgBldr = new MessageBuilder(mEnvCtx
287:                        .getStringTranslator("com.sun.jbi.management"));
288:
289:                try {
290:                    throw new IllegalArgumentException(
291:                            "The argumement state is of invalid type");
292:
293:                } catch (Exception ex) {
294:                    String msg = msgBldr.buildExceptionMessage(
295:                            "testBuildExceptionMessage", ex);
296:                    System.out.println(msg);
297:                }
298:            }
299:
300:            /**
301:             * Test building a Framework message that has Component task results too.
302:             */
303:            public void testBuildFrameworkMessageWithComponentTaskMessages()
304:                    throws Exception {
305:                int numComponents = 5;
306:                java.util.List<ComponentMessageHolder> compMsgs = new java.util.ArrayList<ComponentMessageHolder>();
307:
308:                for (int i = 1; i <= numComponents; i++) {
309:                    ComponentMessageHolder compMsg = new ComponentMessageHolder(
310:                            MessageBuilder.MessageType.INFO.toString());
311:                    compMsg.setComponentName("TestComponent" + i);
312:                    compMsg.setTaskName("TestTask" + i);
313:                    compMsg.setTaskResult(MessageBuilder.TaskResult.SUCCESS
314:                            .toString());
315:
316:                    compMsgs.add(compMsg);
317:                }
318:
319:                // Test
320:                MessageBuilder msgBldr = new MessageBuilder(mEnvCtx
321:                        .getStringTranslator("com.sun.jbi.management"));
322:                String message = msgBldr.buildFrameworkMessage("someTask",
323:                        MessageBuilder.TaskResult.SUCCESS, compMsgs);
324:
325:                assertNotNull(message);
326:                System.out.println(message);
327:                assertTrue(message.indexOf("TestComponent3") != -1);
328:            }
329:
330:            /**
331:             * Test building a composite message with a good response and a exception message
332:             * with a task result of FAILED. Expected composite message should be a SUCCESS 
333:             * with WARNING
334:             */
335:            public void testBuildCompositeMessage() throws Exception {
336:                java.util.Map<String, String> responseMap = new java.util.HashMap();
337:                java.util.Map<String, Throwable> exceptionMap = new java.util.HashMap();
338:
339:                responseMap.put("cluster1-instance1", RESPONSE_1);
340:                exceptionMap.put("cluster1-instance2", new Exception(
341:                        EXCEPTION_1));
342:
343:                // Test
344:                MessageBuilder msgBldr = new MessageBuilder(mEnvCtx
345:                        .getStringTranslator("com.sun.jbi.management"));
346:
347:                com.sun.jbi.management.message.MessageBuilder.Message msg = msgBldr
348:                        .buildCompositeMessage("deploy", responseMap,
349:                                exceptionMap, false);
350:                assertTrue(msg.getMessage().contains("WARNING"));
351:            }
352:
353:            /**
354:             * Test building a composite message with the instance messages with two component
355:             * task results from the same component.
356:             */
357:            public void testBuildCompositeMessageSameComponent()
358:                    throws Exception {
359:                java.util.Map<String, String> responseMap = new java.util.HashMap();
360:                java.util.Map<String, Throwable> exceptionMap = new java.util.HashMap();
361:
362:                responseMap
363:                        .put("cluster1-instance1", SAME_COMPONENT_RESPONSE_1);
364:                responseMap
365:                        .put("cluster1-instance2", SAME_COMPONENT_RESPONSE_2);
366:
367:                // Test
368:                MessageBuilder msgBldr = new MessageBuilder(mEnvCtx
369:                        .getStringTranslator("com.sun.jbi.management"));
370:
371:                com.sun.jbi.management.message.MessageBuilder.Message msg = msgBldr
372:                        .buildCompositeMessage("deploy", responseMap,
373:                                exceptionMap, false);
374:
375:                // Verify there are two component results for manage-binding-1
376:                JbiTaskResult jbiTask = getJbiTaskFromString(msg.getMessage());
377:
378:                List<ComponentTaskResult> compResults = jbiTask
379:                        .getJbiTaskResult().getComponentTaskResult();
380:
381:                assertEquals(2, compResults.size());
382:
383:                for (ComponentTaskResult compResult : compResults) {
384:                    assertEquals("manage-binding-1", compResult
385:                            .getComponentName());
386:                    List<TaskStatusMsg> taskMsgs = compResult
387:                            .getComponentTaskResultDetails()
388:                            .getTaskResultDetails().getTaskStatusMsg();
389:                    assertEquals(4, taskMsgs.size());
390:                }
391:            }
392:
393:            /** Test for well-formed XML strings. */
394:            public void testIsXmlString() throws Exception {
395:                String xml1 = "<test></test>";
396:                String xml2 = "<test></test2>";
397:                String xml3 = "hello";
398:
399:                assertTrue(MessageBuilder.isXmlString(RESPONSE_1));
400:                assertTrue(MessageBuilder.isXmlString(xml1));
401:                assertFalse(MessageBuilder.isXmlString(xml2));
402:                assertFalse(MessageBuilder.isXmlString(xml3));
403:            }
404:
405:            /**
406:             * Test getting the token from a string less than 9 chars.
407:             * and is not a JBI localized message.
408:             */
409:            public void testGetMessageToken1() throws Exception {
410:                String msg = "abc";
411:                String token = MessageBuilder.getMessageToken(msg);
412:
413:                assertEquals("JBIMA0000", token);
414:            }
415:
416:            /**
417:             * Test getting the token from a string less than 9 chars, that starts with JBIUU 
418:             */
419:            public void testGetMessageToken2() throws Exception {
420:
421:                String msg = "JBIU";
422:                String token = MessageBuilder.getMessageToken(msg);
423:
424:                assertEquals("JBIMA0000", token);
425:            }
426:
427:            /**
428:             * Test getting the message string when string less than 9 chars and is not a JBI
429:             * localized message.
430:             */
431:            public void testGetMessageString1() throws Exception {
432:                String msg = "JBIU";
433:                String str = MessageBuilder.getMessageString(msg);
434:
435:                assertEquals("JBIU", str);
436:            }
437:
438:            /**
439:             * Test getting the message string and token when string is 12 chars 
440:             */
441:            public void testGetMessageTokenAndString1() throws Exception {
442:                String msg = "JBIMA1234: A";
443:                String token = MessageBuilder.getMessageToken(msg);
444:                String str = MessageBuilder.getMessageString(msg);
445:                assertEquals("JBIMA1234", token);
446:                assertEquals("A", str);
447:            }
448:
449:            /**
450:             * Test getting the message string and token when string is 9 chars.
451:             */
452:            public void testGetMessageTokenAndString2() throws Exception {
453:                String msg = "JBIMA1234: ";
454:                String token = MessageBuilder.getMessageToken(msg);
455:                String str = MessageBuilder.getMessageString(msg);
456:                assertEquals("JBIMA1234", token);
457:                assertEquals("", str);
458:            }
459:
460:            /**
461:             *
462:             */
463:            private synchronized JAXBContext getJaxbContext() throws Exception {
464:                if (mJaxbContext == null) {
465:                    ClassLoader cl = Class.forName(
466:                            "com.sun.jbi.management.message.JbiTaskResult")
467:                            .getClassLoader();
468:                    mJaxbContext = JAXBContext.newInstance(
469:                            "com.sun.jbi.management.message", cl);
470:                }
471:
472:                return mJaxbContext;
473:            }
474:
475:            private Object unmarshal(StreamSource input) throws Exception {
476:                Unmarshaller reader = getJaxbContext().createUnmarshaller();
477:                return reader.unmarshal(input);
478:            }
479:
480:            /**
481:             * Get the JbiTask Message JAXB object from the message string version
482:             */
483:            private JbiTask getJbiTaskFromString(String jbiTaskMsg)
484:                    throws ManagementException {
485:                try {
486:                    StringBuffer strBuf = new StringBuffer(jbiTaskMsg);
487:                    return (JbiTask) unmarshal(new StreamSource(
488:                            new java.io.StringReader(strBuf.toString())));
489:                } catch (Exception jex) {
490:                    throw new ManagementException(jex);
491:                }
492:            }
493:
494:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.