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: * @(#)TestJBIManagementMessage.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 junit.framework.TestCase;
032: import java.util.Map;
033: import java.util.HashMap;
034:
035: /**
036: * test class
037: * @author Sun Microsystems, Inc.
038: */
039: public class TestJBIManagementMessage extends TestCase {
040: private static String CANNED_SUCCESS_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
041: + "<jbi-task version=\"1.0\" xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
042: + "<jbi-task-result><frmwk-task-result>"
043: + "<frmwk-task-result-details>"
044: + "<task-result-details>"
045: + "<task-id>OPERATION</task-id>"
046: + "<task-result>SUCCESS</task-result>"
047: + "<message-type>INFO</message-type>"
048: + "<task-status-msg>"
049: + "<msg-loc-info>"
050: + "<loc-token>JBIADMIN011</loc-token>"
051: + "<loc-message>Success message.</loc-message>"
052: + "<loc-param>Service Assembly</loc-param>"
053: + "</msg-loc-info>"
054: + "</task-status-msg>"
055: + "</task-result-details>"
056: + "<locale>en</locale>"
057: + "</frmwk-task-result-details>"
058: + "</frmwk-task-result></jbi-task-result>" + "</jbi-task>";
059:
060: private static String CANNED_FAILURE_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
061: + "<jbi-task version=\"1.0\" xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
062: + "<jbi-task-result><frmwk-task-result>"
063: + "<frmwk-task-result-details>"
064: + "<task-result-details>"
065: + "<task-id>OPERATION</task-id>"
066: + "<task-result>FAILED</task-result>"
067: + "<message-type>ERROR</message-type>"
068: + "<task-status-msg>"
069: + "<msg-loc-info>"
070: + "<loc-token>JBIADMIN012</loc-token>"
071: + "<loc-message>Failure message.</loc-message>"
072: + "<loc-param>Service Assembly</loc-param>"
073: + "</msg-loc-info>"
074: + "</task-status-msg>"
075: + "</task-result-details>"
076: + "<locale>en</locale>"
077: + "</frmwk-task-result-details>"
078: + "</frmwk-task-result></jbi-task-result>" + "</jbi-task>";
079:
080: private static String CANNED_EXCEPTION_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
081: + "<jbi-task version=\"1.0\" xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
082: + "<jbi-task-result><frmwk-task-result>"
083: + "<frmwk-task-result-details>"
084: + "<task-result-details>"
085: + "<task-id>OPERATION</task-id>"
086: + "<task-result>FAILED</task-result>"
087: + "<message-type>ERROR</message-type>"
088: + "<task-status-msg>"
089: + "<msg-loc-info>"
090: + "<loc-token>JBIADMIN013</loc-token>"
091: + "<loc-message>Failure message.</loc-message>"
092: + "<loc-param>Service Assembly</loc-param>"
093: + "</msg-loc-info>"
094: + "</task-status-msg>"
095: + "<exception-info>"
096: + "<nesting-level>1</nesting-level>"
097: + "<msg-loc-info>"
098: + "<loc-token>JBIADMIN014</loc-token>"
099: + "<loc-message>First Instance Level Exception Message</loc-message>"
100: + "</msg-loc-info>"
101: + "<stack-trace>First Level Exception Stack Trace</stack-trace>"
102: + "</exception-info>"
103: + "</task-result-details>"
104: + "<locale>en</locale>"
105: + "</frmwk-task-result-details>"
106: + "</frmwk-task-result></jbi-task-result>" + "</jbi-task>";
107:
108: /**
109: * Creates a new instance of TestMgmtMessage
110: * @param aTestName name
111: */
112: public TestJBIManagementMessage(String aTestName) {
113: super (aTestName);
114: }
115:
116: /**
117: * Test creating a composite management message
118: * @throws Exception on error
119: */
120: public void testCreateJBIManagementMessage() throws Exception {
121: // Create a response map for two app vars
122: Map<String, String> responseMap = new HashMap();
123: responseMap.put("applicationVar1", CANNED_SUCCESS_RESPONSE);
124: responseMap.put("applicationVar2", CANNED_SUCCESS_RESPONSE);
125:
126: // Create a management message
127: JBIManagementMessage msg = JBIManagementMessage
128: .createJBIManagementMessage("addApplicationVariables",
129: responseMap, false);
130:
131: assertTrue(msg.isSuccessMsg());
132: assertTrue(msg.isInfoMsgType());
133: assertEquals(4, msg.getFrameworkTaskResult()
134: .getTaskResultInfo().getStatusMessageInfoList().size());
135: }
136:
137: /**
138: * Test creating a composite management message
139: * @throws Exception on error
140: */
141: public void testCreateJBIManagementMessageWithError()
142: throws Exception {
143: // Create a response map for two app vars
144: Map<String, String> responseMap = new HashMap();
145: responseMap.put("applicationVar1", CANNED_SUCCESS_RESPONSE);
146: responseMap.put("applicationVar2", CANNED_FAILURE_RESPONSE);
147:
148: // Create a management message
149: JBIManagementMessage msg = JBIManagementMessage
150: .createJBIManagementMessage("addApplicationVariables",
151: responseMap, false);
152:
153: assertTrue(msg.isWarningMsg());
154: assertEquals(4, msg.getFrameworkTaskResult()
155: .getTaskResultInfo().getStatusMessageInfoList().size());
156: }
157:
158: /**
159: * Test creating a composite management message which has a exception info
160: * @throws Exception on error
161: */
162: public void testCreateJBIManagementMessageWithExceptionInfo()
163: throws Exception {
164: // Create a response map for two app vars
165: Map<String, String> responseMap = new HashMap();
166: responseMap.put("applicationVar1", CANNED_SUCCESS_RESPONSE);
167: responseMap.put("applicationVar2", CANNED_FAILURE_RESPONSE);
168: responseMap.put("applicationVar3", CANNED_EXCEPTION_RESPONSE);
169:
170: // Create a management message
171: JBIManagementMessage msg = JBIManagementMessage
172: .createJBIManagementMessage("addApplicationVariables",
173: responseMap, false);
174:
175: assertTrue(msg.isWarningMsg());
176:
177: assertEquals(6, msg.getFrameworkTaskResult()
178: .getTaskResultInfo().getStatusMessageInfoList().size());
179: assertEquals(2, msg.getFrameworkTaskResult()
180: .getTaskResultInfo().getExceptionInfoList().size());
181: }
182:
183: /**
184: * Test creating a composite management message with requireAllSuccess=true
185: * @throws Exception on error
186: */
187: public void testCreateJBIManagementMessageWithRequireAllSuccess()
188: throws Exception {
189: // Create a response map for two app vars
190: Map<String, String> responseMap = new HashMap();
191: responseMap.put("applicationVar1", CANNED_SUCCESS_RESPONSE);
192: responseMap.put("applicationVar2", CANNED_FAILURE_RESPONSE);
193:
194: // Create a management message
195: JBIManagementMessage msg = JBIManagementMessage
196: .createJBIManagementMessage("addApplicationVariables",
197: responseMap, true);
198:
199: assertTrue(msg.isFailedMsg());
200: assertEquals(4, msg.getFrameworkTaskResult()
201: .getTaskResultInfo().getStatusMessageInfoList().size());
202: }
203:
204: /**
205: * Test creating a composite management message with a plain text exception message
206: * in the response for one application variable
207: * @throws Exception on error
208: */
209: public void testCreateJBIManagementMessageWithExceptionMessage()
210: throws Exception {
211: // Create a response map for two app vars
212: Map<String, String> responseMap = new HashMap();
213: responseMap.put("applicationVar1", CANNED_SUCCESS_RESPONSE);
214: responseMap.put("applicationVar2",
215: "Variable already exists in component");
216:
217: // Create a management message
218: JBIManagementMessage msg = JBIManagementMessage
219: .createJBIManagementMessage("addApplicationVariables",
220: responseMap, false);
221:
222: assertTrue(msg.isWarningMsg());
223: assertEquals(4, msg.getFrameworkTaskResult()
224: .getTaskResultInfo().getStatusMessageInfoList().size());
225: }
226: }
|