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: * @(#)TestJBIResultXmlBuilder.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.IOException;
032: import junit.framework.TestCase;
033:
034: /**
035: * Tests the temporary ui class.
036: *
037: * @author Sun Microsystems, Inc.
038: */
039: public class TestJBIResultXmlBuilder extends TestCase {
040:
041: /**
042: * test case constructor
043: * @param aTestName name of the text
044: */
045: public TestJBIResultXmlBuilder(String aTestName) {
046: super (aTestName);
047: }
048:
049: // ============================= test methods ================================
050:
051: /**
052: * returns test data dir
053: * @return test data dir
054: */
055: private String getTestDataDir() {
056: String srcroot = System.getProperty("junit.srcroot");
057: String testDataDir = srcroot
058: + "/shasta/ui/admin-client/regress/testdata/result/";
059: return testDataDir;
060: }
061:
062: /**
063: * prints the formatted jbi results
064: * @param resultFor main message
065: * @param jbiResultXml xml text
066: * @throws java.lang.Exception on error
067: */
068: private void printFormattedJbiResultXml(String resultFor,
069: String jbiResultXml) throws Exception {
070:
071: // System.out.println();
072: // System.out.println(jbiResultXml);
073: // System.out.println();
074:
075: JBIManagementMessage mgmtMsg = JBIManagementMessage
076: .createJBIManagementMessage(jbiResultXml);
077:
078: String result = mgmtMsg.getMessage();
079:
080: System.out.println();
081: System.out.println(resultFor + " [");
082: System.out.println(result);
083: System.out.println("]");
084: System.out.println();
085: System.out
086: .println("----------------------------------------------------");
087:
088: }
089:
090: /**
091: * testTest
092: * @throws Exception if an unexpected error occurs
093: */
094: public void testCreateMessageOnlyJbiResultXml() throws Exception {
095: String jbiResultXml = JBIResultXmlBuilder.getInstance()
096: .createJbiResultXml("UIANT_TASK",
097: JBIResultXmlBuilder.SUCCESS_RESULT,
098: JBIResultXmlBuilder.INFO_MSG_TYPE, "UIANT000",
099: "This is a message for ant task1", null);
100:
101: printFormattedJbiResultXml(
102: "Esb Result from builder - esb message only",
103: jbiResultXml);
104: }
105:
106: /**
107: * testTest
108: * @throws Exception if an unexpected error occurs
109: */
110: public void testCreateExceptionOnlyJbiResultXml() throws Exception {
111:
112: Exception ex1 = new Exception("First Exception");
113: Exception ex2 = new Exception("Second Exception", ex1);
114: Exception ex = new Exception("Final Exception", ex2);
115:
116: String jbiResultXml = JBIResultXmlBuilder.getInstance()
117: .createJbiResultXml("UIANT_TASK", "UIANT002", ex);
118:
119: printFormattedJbiResultXml(
120: "Esb Result from builder - esb exception only message",
121: jbiResultXml);
122: }
123:
124: /**
125: * testTest
126: * @throws Exception if an unexpected error occurs
127: */
128: public void testCreateMessageAndExceptionJbiResultXml()
129: throws Exception {
130: Exception ex1 = new Exception("First Exception");
131: Exception ex2 = new Exception("Second Exception", ex1);
132: Exception ex = new Exception("Final Exception", ex2);
133:
134: String jbiResultXml = JBIResultXmlBuilder.getInstance()
135: .createJbiResultXml("UIANT_TASK",
136: JBIResultXmlBuilder.FAILED_RESULT,
137: JBIResultXmlBuilder.ERROR_MSG_TYPE, "UIANT002",
138: "This is a task level message", null, ex);
139:
140: printFormattedJbiResultXml(
141: "Esb Result from builder - esb message and exception only message",
142: jbiResultXml);
143: }
144:
145: /**
146: * testTest
147: * @throws Exception if an unexpected error occurs
148: */
149: public void testCreateJbiResultXmlFromI18NBundle() throws Exception {
150: Exception ex1 = new Exception("First Connection Exception");
151: Exception ex2 = new Exception("Second Connection Exception",
152: ex1);
153: Exception ex = new Exception("Final Connection Exception", ex2);
154:
155: String url = "http://host:8989/xjy";
156: // IOException ioEx = new IOException("This is Connection IO Exception");
157:
158: IOException ioEx = new IOException(
159: "IO Error occurred connecting to jmx server");
160: I18NBundle i18nBundle = new I18NBundle("com.sun.jbi.ui.client");
161:
162: JMXConnectionException jmxEx = new JMXConnectionException(
163: JBIResultXmlBuilder.createJbiResultXml(i18nBundle,
164: "jbi.ui.jmx.open.io.error",
165: new Object[] { url }, ioEx), null);
166:
167: // String result = JBIResultXmlBuilder.createFormattedJbiResult(
168: // i18nBundle,"jbi.ui.jmx.open.io.error", new Object[] {url}, ex);
169:
170: // JMXConnectionException jmxEx = new JMXConnectionException(result, ex);
171: // JBIRemoteException rEx = new JBIRemoteException(connEx);
172:
173: // JBIRemoteException rEx = new JBIRemoteException(jmxEx.getMessage(), jmxEx.getCause());
174: JBIRemoteException rEx = new JBIRemoteException(jmxEx);
175: System.out.println("JMX COnnection Exception Message : "
176: + jmxEx.getMessage());
177:
178: System.out
179: .println("JMX Connection results In JBIRemoteException [ ");
180: String result = null;
181: JBIManagementMessage mgmtMsg = rEx
182: .extractJBIManagementMessage();
183: if (mgmtMsg != null) {
184: result = mgmtMsg.getMessage();
185: } else {
186: result = rEx.getMessage();
187: }
188: System.out.println(result);
189:
190: System.out.println("]");
191:
192: System.out
193: .println("JMX Connection results In JBIRemoteException.toString() [ ");
194: System.out.println(rEx.toString());
195: System.out.println("]");
196: }
197:
198: }
|