TextTest xref

    1   /*
    2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    3    *
    4    * This software is open source.
    5    * See the bottom of this file for the licence.
    6    */
    7
    8   package org.dom4j.xpath;
    9
    10  import junit.textui.TestRunner;
    11
    12  import java.util.Iterator;
    13  import java.util.List;
    14
    15  import org.dom4j.AbstractTestCase;
    16  import org.dom4j.Text;
    17
    18  /***
    19   * Test harness for the text() function
    20   *
    21   * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
    22   * @version $Revision: 1.3 $
    23   */
    24  public class TextTest extends AbstractTestCase {
    25      protected static String[] paths = {"text()", "//author/text()"};
    26
    27      public static void main(String[] args) {
    28          TestRunner.run(TextTest.class);
    29      }
    30
    31      // Test case(s)
    32      // -------------------------------------------------------------------------
    33      public void testXPaths() throws Exception {
    34          int size = paths.length;
    35
    36          for (int i = 0; i < size; i++) {
    37              testXPath(paths[i]);
    38          }
    39      }
    40
    41      // Implementation methods
    42      // -------------------------------------------------------------------------
    43      protected void testXPath(String xpath) {
    44          List list = document.selectNodes(xpath);
    45
    46          for (Iterator iter = list.iterator(); iter.hasNext();) {
    47              Object object = iter.next();
    48
    49              log("Found Result: " + object);
    50
    51              assertTrue("Results not Text objects", object instanceof Text);
    52
    53              Text text = (Text) object;
    54
    55              assertTrue("Results should support the parent relationship", text
    56                      .supportsParent());
    57              assertTrue(
    58                      "Results should contain reference to the parent element",
    59                      text.getParent() != null);
    60              assertTrue("Results should not reference to the owning document",
    61                      text.getDocument() != null);
    62          }
    63      }
    64  }
    65
    66  /*
    67   * Redistribution and use of this software and associated documentation
    68   * ("Software"), with or without modification, are permitted provided that the
    69   * following conditions are met:
    70   *
    71   * 1. Redistributions of source code must retain copyright statements and
    72   * notices. Redistributions must also contain a copy of this document.
    73   *
    74   * 2. Redistributions in binary form must reproduce the above copyright notice,
    75   * this list of conditions and the following disclaimer in the documentation
    76   * and/or other materials provided with the distribution.
    77   *
    78   * 3. The name "DOM4J" must not be used to endorse or promote products derived
    79   * from this Software without prior written permission of MetaStuff, Ltd. For
    80   * written permission, please contact dom4j-info@metastuff.com.
    81   *
    82   * 4. Products derived from this Software may not be called "DOM4J" nor may
    83   * "DOM4J" appear in their names without prior written permission of MetaStuff,
    84   * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    85   *
    86   * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    87   *
    88   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    89   * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    90   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    91   * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    92   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    93   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    94   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    95   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    96   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    97   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    98   * POSSIBILITY OF SUCH DAMAGE.
    99   *
    100  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    101  */