001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.engine;
021:
022: import junit.framework.TestCase;
023: import org.apache.axis2.context.MessageContext;
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: import java.lang.reflect.Field;
028:
029: public class MessageContextChangeTest extends TestCase {
030: protected static final Log log = LogFactory
031: .getLog(MessageContextChangeTest.class);
032:
033: private FieldDescription[] knownList = {
034: new FieldDescription("org.apache.commons.logging.Log",
035: "log"),
036: new FieldDescription("java.lang.String", "logCorrelationID"),
037: new FieldDescription("java.lang.String",
038: "logCorrelationIDString"),
039: new FieldDescription("java.lang.String", "myClassName"),
040: new FieldDescription("long", "serialVersionUID"),
041: new FieldDescription("int", "REVISION_1"),
042: new FieldDescription("int", "revisionID"),
043: new FieldDescription("java.lang.ThreadLocal",
044: "currentMessageContext"),
045: new FieldDescription("org.apache.axis2.client.Options",
046: "options"),
047: new FieldDescription("int", "IN_FLOW"),
048: new FieldDescription("int", "IN_FAULT_FLOW"),
049: new FieldDescription("int", "OUT_FLOW"),
050: new FieldDescription("int", "OUT_FAULT_FLOW"),
051: new FieldDescription("java.lang.String", "REMOTE_ADDR"),
052: new FieldDescription("java.lang.String", "TRANSPORT_ADDR"),
053: new FieldDescription("java.lang.String",
054: "TRANSPORT_HEADERS"),
055: new FieldDescription(
056: "org.apache.axiom.attachments.Attachments",
057: "attachments"),
058: new FieldDescription("java.lang.String", "TRANSPORT_OUT"),
059: new FieldDescription("java.lang.String", "TRANSPORT_IN"),
060: new FieldDescription("java.lang.String",
061: "CHARACTER_SET_ENCODING"),
062: new FieldDescription("java.lang.String", "UTF_8"),
063: new FieldDescription("java.lang.String", "UTF_16"),
064: new FieldDescription("java.lang.String",
065: "TRANSPORT_SUCCEED"),
066: new FieldDescription("java.lang.String",
067: "DEFAULT_CHAR_SET_ENCODING"),
068: new FieldDescription("int", "FLOW"),
069: new FieldDescription("java.lang.String",
070: "TRANSPORT_NON_BLOCKING"),
071: new FieldDescription("java.lang.String",
072: "DISABLE_ASYNC_CALLBACK_ON_TRANSPORT_ERROR"),
073: new FieldDescription("boolean", "processingFault"),
074: new FieldDescription("boolean", "paused"),
075: new FieldDescription("boolean", "outputWritten"),
076: new FieldDescription("boolean", "newThreadRequired"),
077: new FieldDescription("boolean", "isSOAP11"),
078: new FieldDescription("java.util.ArrayList",
079: "executionChain"),
080: new FieldDescription("java.util.LinkedList",
081: "executedPhases"),
082: new FieldDescription("boolean", "doingREST"),
083: new FieldDescription("boolean", "doingMTOM"),
084: new FieldDescription("boolean", "doingSwA"),
085: new FieldDescription(
086: "org.apache.axis2.description.AxisMessage",
087: "axisMessage"),
088: new FieldDescription(
089: "org.apache.axis2.description.AxisOperation",
090: "axisOperation"),
091: new FieldDescription(
092: "org.apache.axis2.description.AxisService",
093: "axisService"),
094: new FieldDescription(
095: "org.apache.axis2.description.AxisServiceGroup",
096: "axisServiceGroup"),
097: new FieldDescription(
098: "org.apache.axis2.context.ConfigurationContext",
099: "configurationContext"),
100: new FieldDescription("int", "currentHandlerIndex"),
101: new FieldDescription("int", "currentPhaseIndex"),
102: new FieldDescription("org.apache.axiom.soap.SOAPEnvelope",
103: "envelope"),
104: new FieldDescription(
105: "org.apache.axis2.context.OperationContext",
106: "operationContext"),
107: new FieldDescription("boolean", "responseWritten"),
108: new FieldDescription("boolean", "serverSide"),
109: new FieldDescription(
110: "org.apache.axis2.context.ServiceContext",
111: "serviceContext"),
112: new FieldDescription("java.lang.String", "serviceContextID"),
113: new FieldDescription(
114: "org.apache.axis2.context.ServiceGroupContext",
115: "serviceGroupContext"),
116: new FieldDescription("java.lang.String",
117: "serviceGroupContextId"),
118: new FieldDescription(
119: "org.apache.axis2.context.SessionContext",
120: "sessionContext"),
121: new FieldDescription(
122: "org.apache.axis2.description.TransportOutDescription",
123: "transportOut"),
124: new FieldDescription(
125: "org.apache.axis2.description.TransportInDescription",
126: "transportIn"),
127: new FieldDescription("java.lang.String",
128: "incomingTransportName"),
129: new FieldDescription("java.util.LinkedHashMap",
130: "selfManagedDataMap"),
131: new FieldDescription("boolean", "needsToBeReconciled"),
132: new FieldDescription("int", "selfManagedDataHandlerCount"),
133: new FieldDescription("java.util.ArrayList",
134: "selfManagedDataListHolder"),
135: new FieldDescription("java.util.ArrayList",
136: "metaExecutionChain"),
137: new FieldDescription("java.util.LinkedList", "metaExecuted"),
138: new FieldDescription("int", "metaHandlerIndex"),
139: new FieldDescription("int", "metaPhaseIndex"),
140: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
141: "metaAxisOperation"),
142: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
143: "metaAxisService"),
144: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
145: "metaAxisServiceGroup"),
146: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
147: "metaTransportOut"),
148: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
149: "metaTransportIn"),
150: new FieldDescription("org.apache.axis2.util.MetaDataEntry",
151: "metaAxisMessage"),
152: new FieldDescription("boolean", "reconcileAxisMessage"),
153: new FieldDescription("boolean", "executedPhasesReset"),
154: new FieldDescription("java.lang.String",
155: "selfManagedDataDelimiter"),
156: new FieldDescription("java.lang.Class",
157: "class$org$apache$axis2$context$MessageContext"),
158: new FieldDescription("java.lang.Class",
159: "class$org$apache$axis2$context$SelfManagedDataManager"),
160: new FieldDescription("java.lang.Exception", "failureReason"), };
161:
162: public MessageContextChangeTest(String arg0) {
163: super (arg0);
164: }
165:
166: public void testChange() throws Exception {
167: boolean noChange = true;
168:
169: MessageContext mc = new MessageContext();
170:
171: Class mcClass = mc.getClass();
172:
173: Field[] fields = mcClass.getDeclaredFields();
174: int numberFields = fields.length;
175:
176: int numberKnownFields = knownList.length;
177:
178: if (numberKnownFields != numberFields) {
179: log
180: .error("ERROR: number of actual fields ["
181: + numberFields
182: + "] in MessageContext does not match the expected number ["
183: + numberKnownFields + "]");
184: noChange = false;
185: }
186:
187: // first check the expected fields with the actual fields
188:
189: for (int i = 0; i < numberKnownFields; i++) {
190: // see if this entry is in the actual list
191: String name = knownList[i].getName();
192:
193: Field actualField = findField(fields, name);
194:
195: if (actualField == null) {
196: log.error("ERROR: MessageContext is missing field ["
197: + name + "]");
198: noChange = false;
199: } else {
200: String knownType = knownList[i].getType();
201: String actualType = actualField.getType().getName();
202:
203: if (!knownType.equals(actualType)) {
204: log.error("ERROR: MessageContext field [" + name
205: + "] expected type [" + knownType
206: + "] does not match actual type ["
207: + actualType + "]");
208: noChange = false;
209: }
210: }
211: }
212:
213: // next, check the actual fields with the predefined, known fields
214:
215: for (int j = 0; j < numberFields; j++) {
216: String description = fields[j].toString();
217:
218: // see if this entry is in the predefined list
219: String name = fields[j].getName();
220:
221: FieldDescription fd = findFieldDescription(name);
222:
223: if (fd == null) {
224: log
225: .error("ERROR: MessageContext has new field ["
226: + description
227: + "] that needs to be assessed for message context save/restore functions");
228: noChange = false;
229: } else {
230: String knownType = fd.getType();
231: String actualType = fields[j].getType().getName();
232:
233: if (!knownType.equals(actualType)) {
234: log.error("ERROR: MessageContext field [" + name
235: + "] expected type [" + knownType
236: + "] does not match actual type ["
237: + actualType + "]");
238: noChange = false;
239: }
240: }
241:
242: }
243:
244: assertTrue(noChange);
245: }
246:
247: private Field findField(Field[] fields, String name) {
248:
249: //System.out.println("findField: looking for ["+name+"]");
250:
251: for (int k = 0; k < fields.length; k++) {
252: String fieldName = fields[k].getName();
253: //System.out.println("fieldName["+k+"] = ["+fieldName+"]");
254:
255: if (fieldName.equals(name)) {
256: return fields[k];
257: }
258: }
259: return null;
260: }
261:
262: private FieldDescription findFieldDescription(String name) {
263: for (int k = 0; k < knownList.length; k++) {
264: String fieldName = knownList[k].getName();
265: if (fieldName.equals(name)) {
266: return knownList[k];
267: }
268: }
269: return null;
270: }
271:
272: private class FieldDescription {
273: String type = null;
274: String name = null;
275:
276: // constructor
277: public FieldDescription() {
278: }
279:
280: // constructor
281: public FieldDescription(String t, String n) {
282: type = t;
283: name = n;
284: }
285:
286: public String getType() {
287: return type;
288: }
289:
290: public String getName() {
291: return name;
292: }
293:
294: public void setType(String t) {
295: type = t;
296: }
297:
298: public void setName(String n) {
299: name = n;
300: }
301: }
302:
303: }
|