FileDocCategorySizeDatePackage
OmitTestCase.javaAPI DocApache Axis 1.46596Sat Apr 22 18:57:26 BST 2006test.wsdl.omit

OmitTestCase

public class OmitTestCase extends TestCase
Test nillable elements.
author
Tom Jordahl (tomj@macromedia.com)
author
Dominik Kacprzak (dominik@opentoolbox.com)

Fields Summary
private static final String
AREA_CODE
Constructors Summary
public OmitTestCase(String name)

       
        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        OmitTestCase tester = new OmitTestCase("tester");
        tester.test1OmitEchoPhone();
    
public voidtest1OmitEchoPhone()
Optimistic scenario: - area code is echoed successfully - prefix is not part of XML exchanged between the client and servers - number is passed as null. There does not seem to be a good way to verify what's exchanged over the wire.

        test.wsdl.omit.Omit binding;
        try {
            binding = new test.wsdl.omit.OmitTestLocator().getomit();
        }
        catch (javax.xml.rpc.ServiceException jre) {
            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
        }
        assertTrue("binding is null", binding != null);

        try {
            test.wsdl.omit.Phone input = new test.wsdl.omit.Phone();
            input.setAreaCode(AREA_CODE);

            test.wsdl.omit.Phone out = binding.echoPhone(input);

            assertNotNull("The return value from the operation was null", out);
            assertEquals("area code is incorrect", AREA_CODE, out.getAreaCode());
            assertNull("prefix is not null", out.getPrefix());
            assertNull("number is not null", out.getNumber());
        }
        catch (java.rmi.RemoteException re) {
            throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
        }
    
public voidtest2OmitEchoPhone()
Testing if an exception is thrown when a required elemen is null.

        test.wsdl.omit.Omit binding;
        try {
            binding = new test.wsdl.omit.OmitTestLocator().getomit();
        }
        catch (javax.xml.rpc.ServiceException jre) {
            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
        }
        assertTrue("binding is null", binding != null);

        try {
            test.wsdl.omit.Phone input = new test.wsdl.omit.Phone();
            test.wsdl.omit.Phone out = binding.echoPhone(input);
            throw new junit.framework.AssertionFailedError("web services call succeeded despite of AreaCode being null.");
        }
        catch (java.rmi.RemoteException re) {
            // this is desired
            System.out.println(re);
        }
    
public voidtestGeneratedWSDL()
A simple test to validate if WSDL generated by Axis' ?WSDL properly generates nillable properties.

        boolean testedAreaCode = false;
        boolean testedPrefix = false;
        boolean testedNumber = false;
        // URL for omit's wsdl
        String url = new test.wsdl.omit.OmitTestLocator().getomitAddress() + "?WSDL";
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new junit.framework.AssertionFailedError(e.getLocalizedMessage());
        }
        try {
            Document document = builder.parse(url);
            assertNotNull("WSDL document is null", document);
            NodeList nodes = document.getDocumentElement().getElementsByTagName("element");
            assertTrue("There are no \"elements\" in WSDL document", nodes.getLength() > 0);
            // test elements
            for (int i = 0; i < nodes.getLength(); i++) {
                Element element = (Element) nodes.item(i);
                String name = element.getAttribute("name");
                String nillable = element.getAttribute("nillable");
                if (name.equals("areaCode")) {
                    testedAreaCode = true;
                    assertTrue("nillable attribute for \"areaCode\" element should be empty",
                               nillable.length() == 0);
                }
                if (name.equals("prefix")) {
                    testedPrefix = true;
                    assertTrue("nillable attribute for \"prefix\" element should be empty",
                               nillable.length() == 0);
                }
                if (name.equals("number")) {
                    testedNumber = true;
                    assertTrue("nillable attribute for \"number\" element should be set to \"true\"",
                               nillable.equals("true"));
                }
            }
            // check if all elements were tested
            assertTrue("areaCode element was not validated", testedAreaCode);
            assertTrue("prefix element was not validated", testedPrefix);
            assertTrue("number element was not validated", testedNumber);

        } catch (SAXException e) {
            throw new junit.framework.AssertionFailedError(e.getLocalizedMessage());
        } catch (IOException e) {
            throw new junit.framework.AssertionFailedError(e.getLocalizedMessage());
        }