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: * @(#)TestMgmtMessage.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 TestMgmtMessage extends TestCase {
043:
044: /**
045: * Creates a new instance of TestMgmtMessage
046: * @param aTestName name
047: */
048: public TestMgmtMessage(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: System.out.println("]");
062:
063: System.out.println("******* DEBUG Message **********");
064: System.out.println(msg.getDebugMessage());
065:
066: System.out.println("******* StackTrace **********");
067: msg.printStackTrace(System.out);
068: }
069:
070: /**
071: * test sucess msg
072: * @throws Exception on error
073: */
074: public void testJbiResultNoMessages() throws Exception {
075: String xmlText = this
076: .readMsgFromResource("jbi-result-no-messages.xml");
077: printJbiMgmtMessage("####### JBI Result - NO Messages", xmlText);
078: }
079:
080: /**
081: * test sucess msg
082: * @throws Exception on error
083: */
084: public void testJbiResultAllStatusMessages() throws Exception {
085: String xmlText = this
086: .readMsgFromResource("jbi-result-all-status-msgs.xml");
087: printJbiMgmtMessage("####### JBI Result - All Status Messages",
088: xmlText);
089: }
090:
091: /**
092: * test sucess msg
093: * @throws Exception on error
094: */
095: public void testJbiResultAllExpMessages() throws Exception {
096: String xmlText = this
097: .readMsgFromResource("jbi-result-all-ex-msgs.xml");
098: printJbiMgmtMessage(
099: "####### JBI Result - All Exception Messages", xmlText);
100: }
101:
102: /**
103: * test sucess msg
104: * @throws Exception on error
105: */
106: public void testJbiResultAllMessages() throws Exception {
107: String xmlText = this
108: .readMsgFromResource("jbi-result-all-messages.xml");
109: printJbiMgmtMessage("####### JBI Result - All Messages",
110: xmlText);
111: }
112:
113: /**
114: * test sucess msg
115: * @throws Exception on error
116: */
117: public void testJbiResultFwMsgOnly() throws Exception {
118: String xmlText = this
119: .readMsgFromResource("jbi-result-fw-msg.xml");
120: printJbiMgmtMessage(
121: "####### JBI Result - Framework Message only", xmlText);
122: }
123:
124: /**
125: * test sucess msg
126: * @throws Exception on error
127: */
128: public void testJbiResultFwExpOnly() throws Exception {
129: String xmlText = this
130: .readMsgFromResource("jbi-result-fw-exp.xml");
131: printJbiMgmtMessage(
132: "####### JBI Result - Framework Exception only",
133: xmlText);
134: }
135:
136: /**
137: * test sucess msg
138: * @throws Exception on error
139: */
140: public void testJbiResultFwMsgAndExp() throws Exception {
141: String xmlText = this
142: .readMsgFromResource("jbi-result-fw-msg-and-exp.xml");
143: printJbiMgmtMessage(
144: "####### JBI Result - Framework Message and Exception",
145: xmlText);
146: }
147:
148: /**
149: * test sucess msg
150: * @throws Exception on error
151: */
152: public void testJbiResultCompMsgOnly() throws Exception {
153: String xmlText = this
154: .readMsgFromResource("jbi-result-comp-msg.xml");
155: printJbiMgmtMessage(
156: "####### JBI Result - Component Message only", xmlText);
157: }
158:
159: /**
160: * test sucess msg
161: * @throws Exception on error
162: */
163: public void testJbiResultCompExpOnly() throws Exception {
164: String xmlText = this
165: .readMsgFromResource("jbi-result-comp-exp.xml");
166: printJbiMgmtMessage(
167: "####### JBI Result - Component Exception only",
168: xmlText);
169: }
170:
171: /**
172: * test sucess msg
173: * @throws Exception on error
174: */
175: public void testJbiResultCompMsgAndExp() throws Exception {
176: String xmlText = this
177: .readMsgFromResource("jbi-result-comp-msg-and-exp.xml");
178: printJbiMgmtMessage(
179: "####### JBI Result - Component Message and Exception",
180: xmlText);
181: }
182:
183: /**
184: * test sucess msg
185: * @throws Exception on error
186: */
187: public void testSuccessMsg() throws Exception {
188: String xmlText = this
189: .readMsgFromResource("TestMgmtSuccessMessage.xml");
190:
191: JBIManagementMessage msg = JBIManagementMessage
192: .createJBIManagementMessage(xmlText);
193: System.out.println();
194: PrintWriter writer = new PrintWriter(System.out, true);
195: writer.println("TestMgmtSuccessMessage.xml");
196: writer.println();
197: msg.printMessage(writer);
198: writer.println();
199: writer.println();
200: msg.printStackTrace(writer);
201: this .assertTrue("Expected Success Message", msg.isSuccessMsg());
202: }
203:
204: /**
205: * test sucess msg
206: * @throws Exception on error
207: */
208: public void testSuccessMsg2() throws Exception {
209: String xmlText = this
210: .readMsgFromResource("TestMgmtSuccessMessage2.xml");
211:
212: JBIManagementMessage msg = JBIManagementMessage
213: .createJBIManagementMessage(xmlText);
214: System.out.println();
215: PrintWriter writer = new PrintWriter(System.out, true);
216: writer.println("TestMgmtSuccessMessage2.xml");
217: writer.println();
218: msg.printMessage(writer);
219: writer.println();
220: writer.println();
221: msg.printStackTrace(writer);
222: this .assertTrue("Expected Success Message", msg.isSuccessMsg());
223: }
224:
225: /**
226: * test failure msg
227: * @throws Exception on error
228: */
229: public void testFailureMsg() throws Exception {
230: String xmlText = this
231: .readMsgFromResource("TestMgmtFailureMessage.xml");
232:
233: JBIManagementMessage msg = JBIManagementMessage
234: .createJBIManagementMessage(xmlText);
235: System.out.println();
236: PrintWriter writer = new PrintWriter(System.out, true);
237: writer.println("TestMgmtFailureMessage.xml");
238: writer.println();
239: msg.printMessage(writer);
240: writer.println();
241: writer.println();
242: msg.printStackTrace(writer);
243: this .assertTrue("Expected Failed Message", msg.isFailedMsg());
244:
245: }
246:
247: /**
248: * test exception msg
249: * @throws Exception on error
250: */
251: public void testExceptionMsg() throws Exception {
252: String xmlText = this
253: .readMsgFromResource("TestMgmtExceptionMessage.xml");
254:
255: JBIManagementMessage msg = JBIManagementMessage
256: .createJBIManagementMessage(xmlText);
257: System.out.println();
258: PrintWriter writer = new PrintWriter(System.out, true);
259: writer.println("TestMgmtExceptionMessage.xml");
260: writer.println();
261: msg.printMessage(writer);
262: writer.println();
263: writer.println();
264: msg.printStackTrace(writer);
265: this .assertTrue("Expected Failed Message", msg.isFailedMsg());
266:
267: }
268:
269: /**
270: * test exception msg
271: * @throws Exception on error
272: */
273: public void testExceptionMsg2() throws Exception {
274: String xmlText = this
275: .readMsgFromResource("TestMgmtExceptionMessage2.xml");
276:
277: JBIManagementMessage msg = JBIManagementMessage
278: .createJBIManagementMessage(xmlText);
279: System.out.println();
280: PrintWriter writer = new PrintWriter(System.out, true);
281: writer.println("TestMgmtExceptionMessage2.xml");
282: writer.println();
283: msg.printMessage(writer);
284: writer.println();
285: writer.println();
286: msg.printStackTrace(writer);
287: this .assertTrue("Expected Failed Message", msg.isFailedMsg());
288:
289: }
290:
291: /**
292: * reads the msg from resources
293: * @return xml text
294: * @param resName resource file name
295: */
296: private String readMsgFromResource(String resName) {
297: try {
298: InputStream res = this .getClass().getResourceAsStream(
299: resName);
300: StringWriter strWriter = new StringWriter();
301: PrintWriter writer = new PrintWriter(strWriter);
302: BufferedReader reader = new BufferedReader(
303: new InputStreamReader(res));
304: String ln = null;
305: while ((ln = reader.readLine()) != null) {
306: writer.println(ln);
307: }
308: writer.close();
309: reader.close();
310:
311: return strWriter.getBuffer().toString();
312:
313: } catch (Exception ex) {
314: ex.printStackTrace();
315: return null;
316: }
317: }
318:
319: /**
320: * main
321: * @param args the command line arguments
322: */
323: public static void main(String[] args) {
324: // TODO code application logic here
325: }
326:
327: }
|