MatrixConcatTest 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.io.File;
    13  import java.util.List;
    14
    15  import org.dom4j.AbstractTestCase;
    16  import org.dom4j.io.SAXReader;
    17
    18  /***
    19   * Test harness for the matrix-concat extension function
    20   *
    21   * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
    22   * @version $Revision: 1.3 $
    23   */
    24  public class MatrixConcatTest extends AbstractTestCase {
    25      public static void main(String[] args) {
    26          TestRunner.run(MatrixConcatTest.class);
    27      }
    28
    29      // Test case(s)
    30      // -------------------------------------------------------------------------
    31      public void testMatrixConcat() throws Exception {
    32          String[] exp1 = {"EQUITY_CF1", "EQUITY_CF2", "EQUITY_CF3"};
    33
    34          String[] exp2 = {"EQUITY_BAR_CF1", "EQUITY_BAR_CF2", "EQUITY_BAR_CF3"};
    35
    36          testMatrixConcat("'EQUITY_',/product/cashflows/CashFlow/XREF", exp1);
    37          testMatrixConcat("'EQUITY_','BAR_',/product/cashflows/CashFlow/XREF",
    38                  exp2);
    39      }
    40
    41      // Implementation methods
    42      // -------------------------------------------------------------------------
    43      protected void testMatrixConcat(String path, String[] results)
    44              throws Exception {
    45          log("Using XPath: " + path);
    46
    47          List list = document.selectNodes("matrix-concat(" + path + ")");
    48
    49          log("Found: " + list);
    50
    51          // Object object = list.get(0);
    52          // log( "(0) = " + object + " type: " + object.getClass() );
    53          int size = results.length;
    54          assertTrue("List should contain " + size + " results: " + list, list
    55                  .size() == size);
    56
    57          for (int i = 0; i < size; i++) {
    58              assertEquals(list.get(i), results[i]);
    59          }
    60      }
    61
    62      protected void setUp() throws Exception {
    63          super.setUp();
    64          document = new SAXReader().read(new File("xml/test/product.xml"));
    65      }
    66  }
    67
    68  /*
    69   * Redistribution and use of this software and associated documentation
    70   * ("Software"), with or without modification, are permitted provided that the
    71   * following conditions are met:
    72   *
    73   * 1. Redistributions of source code must retain copyright statements and
    74   * notices. Redistributions must also contain a copy of this document.
    75   *
    76   * 2. Redistributions in binary form must reproduce the above copyright notice,
    77   * this list of conditions and the following disclaimer in the documentation
    78   * and/or other materials provided with the distribution.
    79   *
    80   * 3. The name "DOM4J" must not be used to endorse or promote products derived
    81   * from this Software without prior written permission of MetaStuff, Ltd. For
    82   * written permission, please contact dom4j-info@metastuff.com.
    83   *
    84   * 4. Products derived from this Software may not be called "DOM4J" nor may
    85   * "DOM4J" appear in their names without prior written permission of MetaStuff,
    86   * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    87   *
    88   * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    89   *
    90   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    91   * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    92   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    93   * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    94   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    95   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    96   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    97   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    98   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    99   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    100  * POSSIBILITY OF SUCH DAMAGE.
    101  *
    102  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    103  */