FileDocCategorySizeDatePackage
TestArrayListConversions.javaAPI DocApache Axis 1.45777Sat Apr 22 18:57:28 BST 2006test.encoding

TestArrayListConversions

public class TestArrayListConversions extends TestCase

Fields Summary
private static final String
SERVICE_NAME
private org.apache.axis.server.AxisServer
server
private org.apache.axis.transport.local.LocalTransport
transport
Constructors Summary
public TestArrayListConversions()


      
        super("service");
    
public TestArrayListConversions(String name)

        super(name);
    
Methods Summary
public java.lang.Object[]echoArray(java.lang.Object[] array)

        return array;
    
public java.util.LinkedListechoLinkedList(java.util.LinkedList l)
Service methods - this class is also deployed as an Axis RPC service for convenience. These guys just echo various things.

        return l;
    
public java.util.VectorechoVector(java.util.Vector v)

        return v;
    
private static booleanequals(java.util.List list, java.lang.Object obj)

        if ((list == null) || (obj == null))
            return false;

        if (!obj.getClass().isArray()) return false;

        Object[] array = (Object[]) obj;
        Iterator iter = list.iterator();

        for (int i = 0; i < array.length; i++) {
            if (!(array[i].equals(iter.next()))) {
                return false;
            }
        }

        return true;
    
public static voidmain(java.lang.String[] args)

        TestArrayListConversions tester = new TestArrayListConversions("TestArrayListConversions");
        try {
            tester.setUp();
            tester.testArrayConversion();
            tester.testLinkedListConversion();
            tester.testVectorConversion();
            tester.testReturnAsVector();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
protected voidsetUp()

        try {
            SimpleProvider provider = new SimpleProvider();
            server = new AxisServer(provider);
            transport = new LocalTransport(server);

            SOAPService service = new SOAPService(new RPCProvider());
            service.setEngine(server);

            service.setOption("className", "test.encoding.TestArrayListConversions");
            service.setOption("allowedMethods", "*");

            ServiceDesc desc = service.getInitializedServiceDesc(null);
            desc.setDefaultNamespace(SERVICE_NAME);

            provider.deployService(SERVICE_NAME, service);
        } catch (Exception exp) {
            exp.printStackTrace();
        }

    
public voidtestArrayConversion()

        Call call = new Call(new Service());
        call.setTransport(transport);

        Vector v = new Vector();
        v.addElement("Hi there!");
        v.addElement("This'll be a SOAP Array");

        call.setOperationName(new QName(SERVICE_NAME, "echoArray"));
        Object ret = call.invoke(new Object[]{v});
        if (!equals(v, ret)) assertEquals("Echo Array mangled the result.  Result is underneath\n" + ret, v, ret);
    
public voidtestLinkedListConversion()

        Call call = new Call(new Service());
        call.setTransport(transport);

        LinkedList l = new LinkedList();
        l.add("Linked list item #1");
        l.add("Second linked list item");
        l.add("This will be a SOAP Array then a Vector!");

        call.setOperationName(new QName(SERVICE_NAME, "echoVector"));
        Object ret = call.invoke(new Object[]{l});
        if (!equals(l, ret)) assertEquals("Echo Vector mangled the result.  Result is underneath.\n" + ret, l, ret);
    
public voidtestReturnAsVector()
Test the setReturnClass() API on Call by asking the runtime to give us back a Vector instead of an array. Confirm we get a Vector back, and that it matches the data we send.

        Call call = new Call(new Service());
        call.setTransport(transport);

        LinkedList l = new LinkedList();
        l.add("Linked list item #1");
        l.add("Second linked list item");
        l.add("This will be a SOAP Array then a Vector!");

        call.setOperationName(new QName(SERVICE_NAME, "echoArray"));
        call.addParameter("arg0", null, LinkedList.class, ParameterMode.IN);
        call.setReturnClass(Vector.class);
        Object ret = call.invoke(new Object[]{l});
        assertEquals("Return wasn't a Vector!", Vector.class, ret.getClass());
        Vector v = (Vector)ret;
        assertEquals("Sizes were different", l.size(), v.size());
        for (int i = 0; i < l.size(); i++) {
            String s = (String)l.get(i);
            assertEquals("Value " + i + " didn't match", s, v.get(i));
        }
    
public voidtestVectorConversion()

        Call call = new Call(new Service());
        call.setTransport(transport);

        Vector v = new Vector();
        v.addElement("Hi there!");
        v.addElement("This'll be a SOAP Array and then a LinkedList!");
        call.setOperationName(new QName(SERVICE_NAME, "echoLinkedList"));
        Object ret = call.invoke(new Object[]{v});
        if (!equals(v, ret)) assertEquals("Echo LinkedList mangled the result.  Result is underneath.\n" + ret, v, ret);