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

TestOmittedValues

public class TestOmittedValues extends TestCase
A test which confirms that we can correctly call methods where null arguments are represented by omission from the SOAP envelope.
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
String
header
String
missingParam2
String
footer
Constructors Summary
public TestOmittedValues(String s)


       
        super(s);
    
public TestOmittedValues()

        super("service version");
    
Methods Summary
public java.lang.Stringmethod(java.lang.String p1, java.lang.String p2, java.lang.String p3)

        if (p1.equals("One") && p2 == null && p3.equals("Three")) {
            return "OK!";
        }
        return "Bad arguments!";
    
public voidtestOmittedValue()

        // Set up a server and deploy our service
        BasicServerConfig config = new BasicServerConfig();
        AxisServer server = new AxisServer(config);

        SOAPService service = new SOAPService(new RPCProvider());
        service.setOption("className", "test.encoding.TestOmittedValues");
        service.setOption("allowedMethods", "*");

        ServiceDesc desc = service.getServiceDescription();
        // We need parameter descriptors to make sure we can match by name
        // (the only way omitted==null can work).
        ParameterDesc [] params = new ParameterDesc [] {
            new ParameterDesc(new QName("", "param1"), ParameterDesc.IN, null),
            new ParameterDesc(new QName("", "param2"), ParameterDesc.IN, null),
            new ParameterDesc(new QName("", "param3"), ParameterDesc.IN, null),
        };
        OperationDesc oper = new OperationDesc("method", params, null);
        desc.addOperationDesc(oper);
        config.deployService("testOmittedValue", service);

        String msg = header + missingParam2 + footer;
        Message message = new Message(msg);
        MessageContext context = new MessageContext(server);
        context.setRequestMessage(message);

        Call call = new Call(new Service());

        LocalTransport transport = new LocalTransport(server);
        transport.setRemoteService("testOmittedValue");

        call.setTransport(transport);

        SOAPEnvelope resEnv = call.invoke(message.getSOAPEnvelope());
        RPCElement rpcElem = (RPCElement)resEnv.getFirstBody();
        RPCParam param = (RPCParam)rpcElem.getParams().get(0);
        assertEquals("OK!", param.getObjectValue());