TestClientpublic abstract class TestClient extends Object Test Client for the echo interop service. See the main entrypoint
for more details on usage. |
Fields Summary |
---|
private static InteropTestPortType | binding | private boolean | testModeWhen testMode is true, we throw exceptions up to the caller
instead of recording them and continuing. |
Constructors Summary |
---|
public TestClient()
| public TestClient(boolean testMode)Constructor which sets testMode
this.testMode = testMode;
|
Methods Summary |
---|
protected boolean | equals(java.lang.Object obj1, java.lang.Object obj2)Determine if two objects are equal. Handles nulls and recursively
verifies arrays are equal. Accepts dates within a tolerance of
999 milliseconds.
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<Array.getLength(obj1); i++)
if (!equals(Array.get(obj1,i),Array.get(obj2,i))) return false;
return true;
| public void | execute2A()Execute the 2A tests
// execute the tests
Object output = null;
{
String input = "abccdefg";
try {
output = binding.echoString(input);
verify("echoString", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoString", input, e);
} else {
throw e;
}
}
}
{
String[] input = new String[] {"abc", "def"};
try {
output = binding.echoStringArray(input);
verify("echoStringArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoStringArray", input, e);
} else {
throw e;
}
}
}
{
Integer input = new Integer(42);
try {
output = new Integer( binding.echoInteger(input.intValue()));
verify("echoInteger", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoInteger", input, e);
} else {
throw e;
}
}
}
{
int[] input = new int[] {42};
try {
output = binding.echoIntegerArray(input);
verify("echoIntegerArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoIntegerArray", input, e);
} else {
throw e;
}
}
}
{
Float input = new Float(3.7F);
try {
output = new Float(binding.echoFloat(input.floatValue()));
verify("echoFloat", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoFloat", input, e);
} else {
throw e;
}
}
}
{
float[] input = new float[] {3.7F, 7F};
try {
output = binding.echoFloatArray(input);
verify("echoFloatArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoFloatArray", input, e);
} else {
throw e;
}
}
}
{
SOAPStruct input = new SOAPStruct();
input.setVarInt(5);
input.setVarString("Hello");
input.setVarFloat(103F);
try {
output = binding.echoStruct(input);
verify("echoStruct", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoStruct", input, e);
} else {
throw e;
}
}
}
{
SOAPStruct[] input = new SOAPStruct[] {
new SOAPStruct(),
new SOAPStruct(),
new SOAPStruct()};
input[0].setVarInt(1);
input[0].setVarString("one");
input[0].setVarFloat(1.1F);
input[1].setVarInt(2);
input[1].setVarString("two");
input[1].setVarFloat(2.2F);
input[2].setVarInt(3);
input[2].setVarString("three");
input[2].setVarFloat(3.3F);
try {
output = binding.echoStructArray(input);
verify("echoStructArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoStructArray", input, e);
} else {
throw e;
}
}
}
{
try {
binding.echoVoid();
verify("echoVoid", null, null);
} catch (Exception e) {
if (!testMode) {
verify("echoVoid", null, e);
} else {
throw e;
}
}
}
{
byte[] input = "Base64".getBytes();
try {
output = binding.echoBase64(input);
verify("echoBase64", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoBase64", input, e);
} else {
throw e;
}
}
}
{
HexBinary input = new HexBinary("3344");
try {
output = binding.echoHexBinary(input.getBytes());
verify("echoHexBinary", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoHexBinary", input, e);
} else {
throw e;
}
}
}
Calendar inputDate = Calendar.getInstance();
inputDate.setTimeZone(TimeZone.getTimeZone("GMT"));
inputDate.setTime(new Date());
{
try {
output = binding.echoDate(inputDate);
verify("echoDate", inputDate, output);
} catch (Exception e) {
if (!testMode) {
verify("echoDate", inputDate, e);
} else {
throw e;
}
}
}
{
BigDecimal input = new BigDecimal("3.14159");
try {
output = binding.echoDecimal(input);
verify("echoDecimal", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoDecimal", input, e);
} else {
throw e;
}
}
}
{
Boolean input = Boolean.TRUE;
try {
output = new Boolean( binding.echoBoolean(input.booleanValue()));
verify("echoBoolean", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoBoolean", input, e);
} else {
throw e;
}
}
}
HashMap map = new HashMap();
map.put(new Integer(5), "String Value");
map.put("String Key", inputDate);
{
HashMap input = map;
try {
output = binding.echoMap(input);
verify("echoMap", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoMap", input, e);
} else {
throw e;
}
}
}
HashMap map2 = new HashMap();
map2.put("this is the second map", new Boolean(true));
map2.put("test", new Float(411));
{
HashMap[] input = new HashMap [] {map, map2 };
try {
output = binding.echoMapArray(input);
verify("echoMapArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoMapArray", input, e);
} else {
throw e;
}
}
}
| public void | execute2B()Execute the 2B tests
// execute the tests
Object output = null;
{
SOAPStruct input = new SOAPStruct();
input.setVarInt(5);
input.setVarString("Hello");
input.setVarFloat(103F);
try {
StringHolder outputString = new StringHolder();
IntHolder outputInteger = new IntHolder();
FloatHolder outputFloat = new FloatHolder();
binding.echoStructAsSimpleTypes(input, outputString,
outputInteger, outputFloat);
output = new SOAPStruct();
((SOAPStruct)output).setVarInt(outputInteger.value);
((SOAPStruct)output).setVarString(outputString.value);
((SOAPStruct)output).setVarFloat(outputFloat.value);
verify("echoStructAsSimpleTypes",
input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoStructAsSimpleTypes", input, e);
} else {
throw e;
}
}
}
{
SOAPStruct input = new SOAPStruct();
input.setVarInt(5);
input.setVarString("Hello");
input.setVarFloat(103F);
try {
output = binding.echoSimpleTypesAsStruct(
input.getVarString(), input.getVarInt(), input.getVarFloat());
verify("echoSimpleTypesAsStruct",
input,
output);
} catch (Exception e) {
if (!testMode) {
verify("echoSimpleTypesAsStruct", input, e);
} else {
throw e;
}
}
}
{
String[][] input = new String[2][2];
input[0][0] = "00";
input[0][1] = "01";
input[1][0] = "10";
input[1][1] = "11";
try {
output = binding.echo2DStringArray(input);
verify("echo2DStringArray",
input,
output);
} catch (Exception e) {
if (!testMode) {
verify("echo2DStringArray", input, e);
} else {
throw e;
}
}
}
{
SOAPStruct inputS =new SOAPStruct();
inputS.setVarInt(5);
inputS.setVarString("Hello");
inputS.setVarFloat(103F);
SOAPStructStruct input = new SOAPStructStruct();
input.setVarString("AXIS");
input.setVarInt(1);
input.setVarFloat(3F);
input.setVarStruct(inputS);
try {
output = binding.echoNestedStruct(input);
verify("echoNestedStruct", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNestedStruct", input, e);
} else {
throw e;
}
}
}
{
SOAPArrayStruct input = new SOAPArrayStruct();
input.setVarString("AXIS");
input.setVarInt(1);
input.setVarFloat(3F);
input.setVarArray(new String[] {"one", "two", "three"});
try {
output = binding.echoNestedArray(input);
verify("echoNestedArray", input, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNestedArray", input, e);
} else {
throw e;
}
}
}
| public void | executeAll()Execute all tests.
execute2A();
execute2B();
executeAxisXSD();
| public void | executeAxisXSD()Test custom mapping of xsd types not standardized: xsd:token and
xsd:normalizedString.
Object output = null;
// Test xsd:token
Token tInput = new Token("abccdefg");
try {
output = binding.echoToken(tInput);
verify("echoToken", tInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoToken", tInput, e);
} else {
throw e;
}
}
// Test xsd:normalizedString
NormalizedString nsInput = new NormalizedString("abccdefg");
try {
output = binding.echoNormalizedString(nsInput);
verify("echoNormalizedString", nsInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNormalizedString", nsInput, e);
} else {
throw e;
}
}
// Test xsd:unsignedLong
UnsignedLong ulInput = new UnsignedLong(100);
try {
output = binding.echoUnsignedLong(ulInput);
verify("echoUnsignedLong", ulInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoUnsignedLong", ulInput, e);
} else {
throw e;
}
}
// Test xsd:unsignedInt
UnsignedInt uiInput = new UnsignedInt(101);
try {
output = binding.echoUnsignedInt(uiInput);
verify("echoUnsignedInt", uiInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoUnsignedInt", uiInput, e);
} else {
throw e;
}
}
// Test xsd:unsignedShort
UnsignedShort usInput = new UnsignedShort(102);
try {
output = binding.echoUnsignedShort(usInput);
verify("echoUnsignedShort", usInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoUnsignedShort", usInput, e);
} else {
throw e;
}
}
// Test xsd:unsignedByte
UnsignedByte ubInput = new UnsignedByte(103);
try {
output = binding.echoUnsignedByte(ubInput);
verify("echoUnsignedByte", ubInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoUnsignedByte", ubInput, e);
} else {
throw e;
}
}
// Test xsd:nonNegativeInteger
NonNegativeInteger nniInput = new NonNegativeInteger("12345678901234567890");
try {
output = binding.echoNonNegativeInteger(nniInput);
verify("echoNonNegativeInteger", nniInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNonNegativeInteger", nniInput, e);
} else {
throw e;
}
}
// Test xsd:positiveInteger
PositiveInteger piInput = new PositiveInteger("12345678901234567890");
try {
output = binding.echoPositiveInteger(piInput);
verify("echoPositiveInteger", piInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoPositiveInteger", piInput, e);
} else {
throw e;
}
}
// Test xsd:nonPositiveInteger
NonPositiveInteger npiInput = new NonPositiveInteger("-12345678901234567890");
try {
output = binding.echoNonPositiveInteger(npiInput);
verify("echoNonPositiveInteger", npiInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNonPositiveInteger", npiInput, e);
} else {
throw e;
}
}
// Test xsd:negativeInteger
NegativeInteger niInput = new NegativeInteger("-12345678901234567890");
try {
output = binding.echoNegativeInteger(niInput);
verify("echoNegativeInteger", niInput, output);
} catch (Exception e) {
if (!testMode) {
verify("echoNegativeInteger", niInput, e);
} else {
throw e;
}
}
| public static void | main(java.lang.String[] args)Main entry point. Tests a variety of echo methods and reports
on their results.
Arguments are of the form:
-h localhost -p 8080 -s /soap/servlet/rpcrouter
-h indicats the host
Options opts = new Options(args);
boolean testPerformance = opts.isFlagSet('k") > 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();
}
}
| void | setPassword(java.lang.String password)
((Stub)binding).setPassword(password);
| public void | setURL(java.lang.String url)Set up the call object.
try {
binding = new InteropTestServiceLocator().
getecho(new java.net.URL(url));
// safety first
((InteropTestSoapBindingStub)binding).setTimeout(60000);
((InteropTestSoapBindingStub)binding).setMaintainSession(true);
} catch (Exception exp) {
throw AxisFault.makeFault(exp);
}
| void | setUser(java.lang.String user)
((Stub)binding).setUsername(user);
| protected abstract void | verify(java.lang.String method, java.lang.Object sent, java.lang.Object gotBack)Verify that the object sent was, indeed, the one you got back.
Subclasses are sent to override this with their own output.
|
|