/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package samples.echo ; import org.apache.axis.AxisFault; import org.apache.axis.client.Stub; import org.apache.axis.types.HexBinary; import org.apache.axis.types.NegativeInteger; import org.apache.axis.types.NonNegativeInteger; import org.apache.axis.types.NonPositiveInteger; import org.apache.axis.types.NormalizedString; import org.apache.axis.types.PositiveInteger; import org.apache.axis.types.Token; import org.apache.axis.types.UnsignedByte; import org.apache.axis.types.UnsignedInt; import org.apache.axis.types.UnsignedLong; import org.apache.axis.types.UnsignedShort; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.Options; import javax.xml.rpc.holders.FloatHolder; import javax.xml.rpc.holders.IntHolder; import javax.xml.rpc.holders.StringHolder; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TimeZone; /** * Test Client for the echo interop service. See the main entrypoint * for more details on usage. * * @author Sam Ruby * Modified to use WSDL2Java generated stubs and artifacts by * @author Rich Scheuerle */ public abstract class TestClient { private static InteropTestPortType binding = null; /** * When testMode is true, we throw exceptions up to the caller * instead of recording them and continuing. */ private boolean testMode = false; public TestClient() { } /** * Constructor which sets testMode */ public TestClient(boolean testMode) { this.testMode = testMode; } /** * Determine if two objects are equal. Handles nulls and recursively * verifies arrays are equal. Accepts dates within a tolerance of * 999 milliseconds. */ protected boolean equals(Object obj1, Object obj2) { if (obj1 == null || obj2 == null) return (obj1 == obj2); if (obj1.equals(obj2)) return true; // For comparison purposes, get the array of bytes representing // the HexBinary object. if (obj1 instanceof HexBinary) { obj1 = ((HexBinary) obj1).getBytes(); } if (obj2 instanceof HexBinary) { obj2 = ((HexBinary) obj2).getBytes(); } if (obj1 instanceof Calendar && obj2 instanceof Calendar) { if (Math.abs(((Calendar)obj1).getTime().getTime() - ((Calendar)obj2).getTime().getTime()) < 1000) { return true; } } if ((obj1 instanceof Map) && (obj2 instanceof Map)) { Map map1 = (Map)obj1; Map map2 = (Map)obj2; Set keys1 = map1.keySet(); Set keys2 = map2.keySet(); if (!(keys1.equals(keys2))) return false; // Check map1 is a subset of map2. Iterator i = keys1.iterator(); while (i.hasNext()) { Object key = i.next(); if (!equals(map1.get(key), map2.get(key))) return false; } // Check map2 is a subset of map1. Iterator j = keys2.iterator(); while (j.hasNext()) { Object key = j.next(); if (!equals(map1.get(key), map2.get(key))) return false; } return true; } if (obj1 instanceof List) obj1 = JavaUtils.convert(obj1, Object[].class); if (obj2 instanceof List) obj2 = JavaUtils.convert(obj2, Object[].class); if (!obj2.getClass().isArray()) return false; if (!obj1.getClass().isArray()) return false; if (Array.getLength(obj1) != Array.getLength(obj2)) return false; for (int i=0; i 0; boolean allTests = opts.isFlagSet('A') > 0; boolean onlyB = opts.isFlagSet('b') > 0; boolean testMode = opts.isFlagSet('t') > 0; // set up tests so that the results are sent to System.out TestClient client; if (testPerformance) { client = new TestClient(testMode) { public void verify(String method, Object sent, Object gotBack) { } }; } else { client = new TestClient(testMode) { public void verify(String method, Object sent, Object gotBack) { String message; if (this.equals(sent, gotBack)) { message = "OK"; } else { if (gotBack instanceof Exception) { if (gotBack instanceof AxisFault) { message = "Fault: " + ((AxisFault)gotBack).getFaultString(); } else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); message = "Exception: "; ((Exception)gotBack).printStackTrace(pw); message += sw.getBuffer().toString(); } } else { message = "Fail:" + gotBack + " expected " + sent; } } // Line up the output String tab = ""; int l = method.length(); while (l < 25) { tab += " "; l++; } System.out.println(method + tab + " " + message); } }; } // set up the call object client.setURL(opts.getURL()); client.setUser(opts.getUser()); client.setPassword(opts.getPassword()); if (testPerformance) { long startTime = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { if (allTests) { client.executeAll(); } else if (onlyB) { client.execute2B(); } else { client.execute2A(); } } long stopTime = System.currentTimeMillis(); System.out.println("That took " + (stopTime - startTime) + " milliseconds"); } else { if (allTests) { client.executeAll(); } else if (onlyB) { client.execute2B(); } else { client.execute2A(); } } } }