1 package org.apache.torque.util; 2 3 21 22 import java.lang.reflect.Array ; 23 24 import junit.framework.TestCase; 25 26 import org.apache.torque.adapter.DB; 27 import org.apache.torque.adapter.DBFactory; 28 29 36 public class SqlExpressionTest extends TestCase 37 { 38 private DB db = null; 39 40 41 45 public SqlExpressionTest(String arg0) 46 { 47 super(arg0); 48 } 49 50 53 public void setUp() 54 { 55 try 56 { 57 db = DBFactory.create("mysql"); 58 } 59 catch (Exception ex) 60 { 61 ex.printStackTrace(); 62 } 63 } 64 65 68 public void testBuildInnerJoinStringString() 69 { 70 String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB"); 71 assertEquals(result, "TA.COLA=TB.COLB"); 72 } 73 74 77 public void testBuildInnerJoinStringStringbooleanDB() 78 { 79 String result = SqlExpression.buildInnerJoin("TA.COLA", "TB.COLB", 80 true, db); 81 assertEquals(result, "TA.COLA=TB.COLB"); 82 } 83 84 87 public void testBuildInStringObjectSqlEnumbooleanDB() 88 { 89 String [] values = new String [] { "42", "43", "44" }; 90 String result = SqlExpression.buildIn("COL", values, SqlEnum.IN, 91 true, db); 92 if (result.equals("COL IN ('42','43','44')")) 95 { 96 assertEquals(result, "COL IN ('42','43','44')"); 98 } 99 else 100 { 101 assertEquals(result, "COL IN ('43','44','42')"); 103 } 104 } 105 106 public void testLargeBuildInStringObjectSqlEnumbooleanDB() 107 { 108 int size = 10000; 109 String [] values = new String [size]; 110 for (int i = 0; i < size; i++) 111 { 112 Array.set(values, i, String.valueOf(i)); 113 } 114 long start = System.currentTimeMillis(); 115 String result = SqlExpression.buildIn("COL", values, SqlEnum.IN, 116 true, db); 117 long end = System.currentTimeMillis(); 118 System.out.println("large buildIn took " + (end - start) + " milliseconds"); 119 } 120 121 124 public void testBuildLike() 125 { 126 String result = SqlExpression.buildLike( 127 "COL", "fre%", SqlEnum.LIKE, false, db); 128 assertEquals("COL LIKE fre%", result); 129 130 result = SqlExpression.buildLike( 131 "COL", "50\\\\%", SqlEnum.LIKE, false, db); 132 assertEquals("COL = 50%", result); 133 } 134 } 135 | Popular Tags |