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: * @(#)TestClusterMgmtMessage.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.common;
030:
031: import java.io.BufferedReader;
032: import java.io.InputStream;
033: import java.io.InputStreamReader;
034: import java.io.PrintWriter;
035: import java.io.StringWriter;
036: import junit.framework.TestCase;
037:
038: /**
039: * test class
040: * @author Sun Microsystems, Inc.
041: */
042: public class TestClusterMgmtMessage extends TestCase {
043:
044: /**
045: * Creates a new instance of TestMgmtMessage
046: * @param aTestName name
047: */
048: public TestClusterMgmtMessage(String aTestName) {
049: super (aTestName);
050: }
051:
052: private void printJbiMgmtMessage(String title, String msgXml) {
053: if (title == null) {
054: title = "########## Formatted JBI Results ###########";
055: }
056: System.out.println(title + "[");
057:
058: JBIManagementMessage msg = JBIManagementMessage
059: .createJBIManagementMessage(msgXml);
060: System.out.println(msg.getMessage());
061:
062: System.out.println("]");
063:
064: // System.out.println("******* DEBUG Message **********");
065: // System.out.println(msg.getDebugMessage());
066: //
067: // System.out.println("******* StackTrace **********");
068: // msg.printStackTrace(System.out);
069: }
070:
071: private void printESBResults(String title, String msgXml) {
072: if (title == null) {
073: title = "########## Formatted ESB Results ###########";
074: }
075: System.out.println(title + "[");
076: ESBResultFormatter formatter = new ESBResultFormatter();
077: String msg = formatter.getFormattedESBResult(msgXml);
078: System.out.println(msg);
079: System.out.println("]");
080:
081: }
082:
083: //// /**
084: //// * test sucess msg
085: //// * @throws Exception on error
086: //// */
087: //// public void testJbiResultNoMessages() throws Exception
088: //// {
089: //// String xmlText = this.readMsgFromResource("jbi-result-no-messages.xml");
090: //// printJbiMgmtMessage("####### JBI Result - NO Messages", xmlText);
091: //// }
092: ////
093: /**
094: * test sucess msg
095: * @throws Exception on error
096: */
097: public void testClusterResultAllStatusMessages() throws Exception {
098: String xmlText = this
099: .readMsgFromResource("jbi-result-cluster-all-status-msgs.xml");
100: printESBResults("####### ESB Result - All Status Messages",
101: xmlText);
102: }
103:
104: /**
105: * test sucess msg
106: * @throws Exception on error
107: */
108: public void testClusterResultAllExpMessages() throws Exception {
109: String xmlText = this
110: .readMsgFromResource("jbi-result-cluster-all-ex-msgs.xml");
111: printESBResults("####### ESB Result - All Exception Messages",
112: xmlText);
113: }
114:
115: /**
116: * test sucess msg
117: * @throws Exception on error
118: */
119: public void testClusterResultAllMessages() throws Exception {
120: String esbResultXml = this
121: .readMsgFromResource("jbi-result-cluster-all-messages.xml");
122: printESBResults("####### ESB Result - All Messages",
123: esbResultXml);
124: // String jbiResultXml = this.readMsgFromResource("jbi-result-all-messages.xml");
125: // printJbiMgmtMessage(null, jbiResultXml);
126: }
127:
128: /**
129: * test sucess msg
130: * @throws Exception on error
131: */
132: public void testClusterResultFwMsgOnly() throws Exception {
133: String xmlText = this
134: .readMsgFromResource("jbi-result-cluster-fw-msg.xml");
135: printESBResults("####### ESB Result - Framework Message only",
136: xmlText);
137: }
138:
139: /**
140: * test sucess msg
141: * @throws Exception on error
142: */
143: public void testClusterResultFwExpOnly() throws Exception {
144: String xmlText = this
145: .readMsgFromResource("jbi-result-cluster-fw-exp.xml");
146: printESBResults(
147: "####### ESB Result - Framework Exception only",
148: xmlText);
149: }
150:
151: /**
152: * test sucess msg
153: * @throws Exception on error
154: */
155: public void testClusterResultFwMsgAndExp() throws Exception {
156: String xmlText = this
157: .readMsgFromResource("jbi-result-cluster-fw-msg-and-exp.xml");
158: printESBResults(
159: "####### ESB Result - Framework Message and Exception",
160: xmlText);
161: }
162:
163: /**
164: * test sucess msg
165: * @throws Exception on error
166: */
167: public void testClusterResultCompMsgOnly() throws Exception {
168: String xmlText = this
169: .readMsgFromResource("jbi-result-cluster-comp-msg.xml");
170: printESBResults("####### ESB Result - Component Message only",
171: xmlText);
172: }
173:
174: /**
175: * test sucess msg
176: * @throws Exception on error
177: */
178: public void testClusterResultCompExpOnly() throws Exception {
179: String xmlText = this
180: .readMsgFromResource("jbi-result-cluster-comp-exp.xml");
181: printESBResults(
182: "####### ESB Result - Component Exception only",
183: xmlText);
184: }
185:
186: /**
187: * test sucess msg
188: * @throws Exception on error
189: */
190: public void testClusterResultCompMsgAndExp() throws Exception {
191: String xmlText = this
192: .readMsgFromResource("jbi-result-cluster-comp-msg-and-exp.xml");
193: printJbiMgmtMessage(
194: "####### ESB Result - Component Message and Exception",
195: xmlText);
196: }
197:
198: /**
199: * test sucess msg
200: * @throws Exception on error
201: */
202: public void testClusterResultBadXml() throws Exception {
203: String xmlText = this
204: .readMsgFromResource("jbi-result-cluster-bad-xml.xml");
205: printJbiMgmtMessage("####### ESB Result - Bad xml", xmlText);
206:
207: JBIManagementMessage msg = JBIManagementMessage
208: .createJBIManagementMessage(xmlText);
209: System.out.println("Old mgmt msg [");
210: System.out.println(msg.getMessageDeprecated("verbose"));
211: System.out.println("]");
212: }
213:
214: //// /**
215: //// * test sucess msg
216: //// * @throws Exception on error
217: //// */
218: //// public void testSuccessMsg() throws Exception
219: //// {
220: //// String xmlText = this.readMsgFromResource("TestMgmtSuccessMessage.xml");
221: ////
222: //// JBIManagementMessage msg =
223: //// JBIManagementMessage.createJBIManagementMessage(xmlText);
224: //// System.out.println();
225: //// PrintWriter writer = new PrintWriter(System.out, true);
226: //// writer.println("TestMgmtSuccessMessage.xml");
227: //// writer.println();
228: //// msg.printMessage(writer);
229: //// writer.println();
230: //// writer.println();
231: //// msg.printStackTrace(writer);
232: //// this.assertTrue("Expected Success Message", msg.isSuccessMsg());
233: //// }
234: ////
235: //// /**
236: //// * test sucess msg
237: //// * @throws Exception on error
238: //// */
239: //// public void testSuccessMsg2() throws Exception
240: //// {
241: //// String xmlText = this.readMsgFromResource("TestMgmtSuccessMessage2.xml");
242: ////
243: //// JBIManagementMessage msg =
244: //// JBIManagementMessage.createJBIManagementMessage(xmlText);
245: //// System.out.println();
246: //// PrintWriter writer = new PrintWriter(System.out, true);
247: //// writer.println("TestMgmtSuccessMessage2.xml");
248: //// writer.println();
249: //// msg.printMessage(writer);
250: //// writer.println();
251: //// writer.println();
252: //// msg.printStackTrace(writer);
253: //// this.assertTrue("Expected Success Message", msg.isSuccessMsg());
254: //// }
255: ////
256: ////
257: //// /**
258: //// * test failure msg
259: //// * @throws Exception on error
260: //// */
261: //// public void testFailureMsg() throws Exception
262: //// {
263: //// String xmlText = this.readMsgFromResource("TestMgmtFailureMessage.xml");
264: ////
265: //// JBIManagementMessage msg =
266: //// JBIManagementMessage.createJBIManagementMessage(xmlText);
267: //// System.out.println();
268: //// PrintWriter writer = new PrintWriter(System.out, true);
269: //// writer.println("TestMgmtFailureMessage.xml");
270: //// writer.println();
271: //// msg.printMessage(writer);
272: //// writer.println();
273: //// writer.println();
274: //// msg.printStackTrace(writer);
275: //// this.assertTrue("Expected Failed Message", msg.isFailedMsg());
276: ////
277: //// }
278: ////
279: //// /**
280: //// * test exception msg
281: //// * @throws Exception on error
282: //// */
283: //// public void testExceptionMsg() throws Exception
284: //// {
285: //// String xmlText = this.readMsgFromResource("TestMgmtExceptionMessage.xml");
286: ////
287: //// JBIManagementMessage msg =
288: //// JBIManagementMessage.createJBIManagementMessage(xmlText);
289: //// System.out.println();
290: //// PrintWriter writer = new PrintWriter(System.out, true);
291: //// writer.println("TestMgmtExceptionMessage.xml");
292: //// writer.println();
293: //// msg.printMessage(writer);
294: //// writer.println();
295: //// writer.println();
296: //// msg.printStackTrace(writer);
297: //// this.assertTrue("Expected Failed Message", msg.isFailedMsg());
298: ////
299: //// }
300: ////
301: //// /**
302: //// * test exception msg
303: //// * @throws Exception on error
304: //// */
305: //// public void testExceptionMsg2() throws Exception
306: //// {
307: //// String xmlText = this.readMsgFromResource("TestMgmtExceptionMessage2.xml");
308: ////
309: //// JBIManagementMessage msg =
310: //// JBIManagementMessage.createJBIManagementMessage(xmlText);
311: //// System.out.println();
312: //// PrintWriter writer = new PrintWriter(System.out, true);
313: //// writer.println("TestMgmtExceptionMessage2.xml");
314: //// writer.println();
315: //// msg.printMessage(writer);
316: //// writer.println();
317: //// writer.println();
318: //// msg.printStackTrace(writer);
319: //// this.assertTrue("Expected Failed Message", msg.isFailedMsg());
320: ////
321: //// }
322: ////
323:
324: /**
325: * reads the msg from resources
326: * @return xml text
327: * @param resName resource file name
328: */
329: private String readMsgFromResource(String resName) {
330: try {
331: InputStream res = this .getClass().getResourceAsStream(
332: resName);
333: StringWriter strWriter = new StringWriter();
334: PrintWriter writer = new PrintWriter(strWriter);
335: BufferedReader reader = new BufferedReader(
336: new InputStreamReader(res));
337: String ln = null;
338: while ((ln = reader.readLine()) != null) {
339: writer.println(ln);
340: }
341: writer.close();
342: reader.close();
343:
344: return strWriter.getBuffer().toString();
345:
346: } catch (Exception ex) {
347: ex.printStackTrace();
348: return null;
349: }
350: }
351:
352: /**
353: * main
354: * @param args the command line arguments
355: */
356: public static void main(String[] args) {
357: // TODO code application logic here
358: }
359:
360: }
|