1 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 ; 19 import java.util.List ; 20 21 26 public class TestMatrixConcat extends AbstractTestCase { 27 28 public static void main( String [] args ) { 29 TestRunner.run( suite() ); 30 } 31 32 public static Test suite() { 33 return new TestSuite( TestMatrixConcat.class ); 34 } 35 36 public TestMatrixConcat(String name) { 37 super(name); 38 } 39 40 public void testDummy() throws Exception { 43 } 44 45 public void testMatrixConcat() throws Exception { 46 String [] results1 = { 47 "EQUITY_CF1", 48 "EQUITY_CF2", 49 "EQUITY_CF3" 50 }; 51 52 String [] 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 protected void testMatrixConcat(String path, String [] results) throws Exception { 67 log( "Using XPath: " + path ); 68 69 List list = document.selectNodes( path ); 70 71 log( "Found: " + list ); 72 73 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 { 85 document = new SAXReader().read( new File ( "xml/test/product.xml" ) ); 86 } 87 } 88 89 90 91 92 136 | Popular Tags |