1 package org.apache.torque.util; 2 3 21 22 import org.apache.torque.BaseTestCase; 23 import org.apache.torque.TorqueException; 24 25 32 public class SqlBuilderTest extends BaseTestCase 33 { 34 39 public SqlBuilderTest(String name) 40 { 41 super(name); 42 } 43 44 public void testExtractTableName() throws TorqueException 45 { 46 String columnName = "table.column"; 48 String tableName = SQLBuilder.getTableName(columnName, null); 49 assertEquals("table", tableName); 50 51 columnName = "schema.table.column"; 52 tableName = SQLBuilder.getTableName(columnName, null); 53 assertEquals("schema.table", tableName); 54 55 columnName = "function(table.column)"; 57 tableName = SQLBuilder.getTableName(columnName, null); 58 assertEquals("table", tableName); 59 60 columnName = "function(1,table.column,2)"; 61 tableName = SQLBuilder.getTableName(columnName, null); 62 assertEquals("table", tableName); 63 64 columnName = "table.column < 10"; 66 tableName = SQLBuilder.getTableName(columnName, null); 67 assertEquals("table", tableName); 68 69 columnName = "table.column<10"; 70 tableName = SQLBuilder.getTableName(columnName, null); 71 assertEquals("table", tableName); 72 73 columnName = "10 > table.column"; 74 tableName = SQLBuilder.getTableName(columnName, null); 75 assertEquals("table", tableName); 76 77 columnName = "10>table.column"; 78 tableName = SQLBuilder.getTableName(columnName, null); 79 assertEquals("table", tableName); 80 81 columnName = "10>table.column"; 82 tableName = SQLBuilder.getTableName(columnName, null); 83 assertEquals("table", tableName); 84 85 columnName = "table.column in (1,2,3)"; 87 tableName = SQLBuilder.getTableName(columnName, null); 88 assertEquals("table", tableName); 89 90 columnName = "*"; 92 tableName = SQLBuilder.getTableName(columnName, null); 93 assertEquals(null, tableName); 94 95 columnName = "count(*)"; 97 tableName = SQLBuilder.getTableName(columnName, null); 98 assertEquals(null, tableName); 99 100 columnName = ""; 102 try 103 { 104 tableName = SQLBuilder.getTableName(columnName, null); 105 fail("getTableName() should fail for empty column name"); 106 } 107 catch (TorqueException e) 108 { 109 } 110 111 columnName = null; 112 try 113 { 114 tableName = SQLBuilder.getTableName(columnName, null); 115 fail("getTableName() should fail for null as column name"); 116 } 117 catch (TorqueException e) 118 { 119 } 120 121 columnName = "column"; 123 try 124 { 125 tableName = SQLBuilder.getTableName(columnName, null); 126 fail("getTableName() should fail for column name " 127 + "without a dot or wildcard"); 128 } 129 catch (TorqueException e) 130 { 131 } 132 133 } 134 } 135 | Popular Tags |