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