You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by to...@apache.org on 2004/11/21 16:41:17 UTC

cvs commit: ws-axis/java/test/wsdl/omit OmitTestCase.java

tomj        2004/11/21 07:41:17

  Modified:    java/test/wsdl/omit OmitTestCase.java
  Log:
  Patch from Dominik Kacprzak [dominik@opentoolbox.com]:
   I extended test.wsdl.omit.OmitTestCase to test a fix for AXIS-1670.
  
  Revision  Changes    Path
  1.8       +72 -2     ws-axis/java/test/wsdl/omit/OmitTestCase.java
  
  Index: OmitTestCase.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/omit/OmitTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OmitTestCase.java	18 Nov 2004 17:00:41 -0000	1.7
  +++ OmitTestCase.java	21 Nov 2004 15:41:17 -0000	1.8
  @@ -33,6 +33,22 @@
   
   package test.wsdl.omit;
   
  +import org.w3c.dom.Document;
  +import org.w3c.dom.NodeList;
  +import org.w3c.dom.Element;
  +import org.xml.sax.SAXException;
  +
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.ParserConfigurationException;
  +import java.io.IOException;
  +
  +/**
  + * Test nillable elements.
  + *
  + * @author Tom Jordahl (tomj@macromedia.com)
  + * @author Dominik Kacprzak (dominik@opentoolbox.com)
  + */
   public class OmitTestCase extends junit.framework.TestCase {
       private static final String AREA_CODE = "111";
       public OmitTestCase(String name) {
  @@ -72,7 +88,7 @@
       }
   
       /**
  -     * Validating that an exception is thrown when area code (which is a required element) is null:
  +     * Testing if an exception is thrown when a required elemen is null.
        */
       public void test2OmitEchoPhone() {
           test.wsdl.omit.Omit binding;
  @@ -95,9 +111,63 @@
           }
       }
   
  +    /**
  +     * A simple test to validate if WSDL generated by Axis' ?WSDL properly
  +     * generates nillable properties.
  +     */
  +    public void testGeneratedWSDL() {
  +        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());
  +        }
  +    }
  +
       public static void main(String[] args) {
           OmitTestCase tester = new OmitTestCase("tester");
           tester.test1OmitEchoPhone();
       }
   }
  -