KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > xpath > TestMatrixConcat


1 /*
2  * Copyright 2001 (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.1 2003/07/07 10:30:30 per_nyfelt Exp $
8  */

9
10 package test.dom4j.xpath;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.io.SAXReader;
16 import test.dom4j.AbstractTestCase;
17
18 import java.io.File JavaDoc;
19 import java.util.List JavaDoc;
20
21 /** Test harness for the matrix-concat extension function
22   *
23   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
24   * @version $Revision: 1.1 $
25   */

26 public class TestMatrixConcat extends AbstractTestCase {
27
28     public static void main( String JavaDoc[] args ) {
29         TestRunner.run( suite() );
30     }
31
32     public static Test suite() {
33         return new TestSuite( TestMatrixConcat.class );
34     }
35
36     public TestMatrixConcat(String JavaDoc name) {
37         super(name);
38     }
39
40     // Test case(s)
41
//-------------------------------------------------------------------------
42
public void testDummy() throws Exception JavaDoc {
43     }
44
45     public void testMatrixConcat() throws Exception JavaDoc {
46         String JavaDoc[] results1 = {
47             "EQUITY_CF1",
48             "EQUITY_CF2",
49             "EQUITY_CF3"
50         };
51
52         String JavaDoc[] results2 = {
53             "EQUITY_BAR_CF1",
54             "EQUITY_BAR_CF2",
55             "EQUITY_BAR_CF3"
56         };
57
58         testMatrixConcat( "matrix-concat('EQUITY_',/product/cashflows/CashFlow/XREF)", results1 );
59         testMatrixConcat( "matrix-concat('EQUITY_','BAR_',/product/cashflows/CashFlow/XREF)", results2 );
60         testMatrixConcat( "matrix-concat(/product/equity/IDENTIFIER,/product/cashflows/CashFlow/XREF)", results1 );
61     }
62
63
64     // Implementation methods
65
//-------------------------------------------------------------------------
66
protected void testMatrixConcat(String JavaDoc path, String JavaDoc[] results) throws Exception JavaDoc {
67         log( "Using XPath: " + path );
68
69         List JavaDoc list = document.selectNodes( path );
70
71         log( "Found: " + list );
72
73         //Object object = list.get(0);
74
//log( "(0) = " + object + " type: " + object.getClass() );
75

76         int size = results.length;
77         assertTrue( "List should contain " + size + " results: " + list, list.size() == size );
78
79         for ( int i = 0; i < size; i++ ) {
80             assertEquals( list.get(i), results[i] );
81         }
82     }
83
84     protected void setUp() throws Exception JavaDoc {
85         document = new SAXReader().read( new File JavaDoc( "xml/test/product.xml" ) );
86     }
87 }
88
89
90
91
92 /*
93  * Redistribution and use of this software and associated documentation
94  * ("Software"), with or without modification, are permitted provided
95  * that the following conditions are met:
96  *
97  * 1. Redistributions of source code must retain copyright
98  * statements and notices. Redistributions must also contain a
99  * copy of this document.
100  *
101  * 2. Redistributions in binary form must reproduce the
102  * above copyright notice, this list of conditions and the
103  * following disclaimer in the documentation and/or other
104  * materials provided with the distribution.
105  *
106  * 3. The name "DOM4J" must not be used to endorse or promote
107  * products derived from this Software without prior written
108  * permission of MetaStuff, Ltd. For written permission,
109  * please contact dom4j-info@metastuff.com.
110  *
111  * 4. Products derived from this Software may not be called "DOM4J"
112  * nor may "DOM4J" appear in their names without prior written
113  * permission of MetaStuff, Ltd. DOM4J is a registered
114  * trademark of MetaStuff, Ltd.
115  *
116  * 5. Due credit should be given to the DOM4J Project
117  * (http://dom4j.org/).
118  *
119  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
120  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
121  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
122  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
123  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
124  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
125  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
126  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
127  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
128  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
129  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
130  * OF THE POSSIBILITY OF SUCH DAMAGE.
131  *
132  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
133  *
134  * $Id: TestMatrixConcat.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
135  */

136
Popular Tags