1 24 25 package org.objectweb.cjdbc.scenario.standalone.sql.schema; 26 27 import java.sql.SQLException ; 28 import java.sql.Types ; 29 import java.util.ArrayList ; 30 31 import org.objectweb.cjdbc.common.sql.schema.DatabaseColumn; 32 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable; 33 import org.objectweb.cjdbc.scenario.templates.NoTemplate; 34 35 41 public class DatabaseTableTest extends NoTemplate 42 { 43 44 private DatabaseTable t1, t2, t3, t4, t5, t6; 45 46 47 private DatabaseColumn c1, c2, c3, c4, c5, c6, c7, c8; 48 49 52 protected void setUp() 53 { 54 c1 = new DatabaseColumn("id", true, Types.INTEGER); 55 c2 = new DatabaseColumn("name", false, Types.VARCHAR); 56 c3 = new DatabaseColumn("rating", false, Types.INTEGER); 57 c4 = new DatabaseColumn("balance", false, Types.FLOAT); 58 c5 = new DatabaseColumn("creation_date", false, Types.TIMESTAMP); 59 60 c6 = new DatabaseColumn("nickname", false, Types.VARCHAR); 61 c7 = new DatabaseColumn("comment", false, Types.VARCHAR); 62 c8 = new DatabaseColumn("name", true, Types.VARCHAR); 63 64 t1 = new DatabaseTable("users", 5); 65 t1.addColumn(c1); 66 t1.addColumn(c2); 67 t1.addColumn(c3); 68 t1.addColumn(c4); 69 t1.addColumn(c5); 70 71 t2 = new DatabaseTable("users-merge-compatible", 2); 72 t2.addColumn(c6); 73 t2.addColumn(c7); 74 75 t3 = new DatabaseTable("users-merge-incompatible", 3); 76 t3.addColumn(c6); 77 t3.addColumn(c7); 78 t3.addColumn(c8); 79 80 t4 = new DatabaseTable("users", 5); 82 t4.addColumn(c1); 83 t4.addColumn(c2); 84 t4.addColumn(c3); 85 t4.addColumn(c4); 86 t4.addColumn(c5); 87 88 t5 = new DatabaseTable("users", 5); 90 t5.addColumn(c1); 91 t5.addColumn(c2); 92 t5.addColumn(c3); 93 t5.addColumn(c8); 94 t5.addColumn(c5); 95 96 t6 = new DatabaseTable("users", 1); 97 t6.addColumn(c6); 98 } 99 100 103 public void testMergeColumns() 104 { 105 try 106 { 107 t1.mergeColumns(t3); 108 fail("SQLException not thrown with two incompatible tables"); 109 } 110 catch (SQLException ignore) 111 { 112 } 113 114 try 115 { 116 t1.mergeColumns(t2); 117 t1.mergeColumns(t1); 118 } 119 catch (SQLException e) 120 { 121 fail("SQLException thrown with two compatible tables (" + e + ")"); 122 } 123 124 assertTrue(t1.getColumn("nickname").equals(c6)); 125 assertTrue(t1.getColumn("comment").equals(c7)); 126 } 127 128 131 public void testGetColumns() 132 { 133 ArrayList columns = new ArrayList (); 134 columns.add(c1); 135 columns.add(c2); 136 columns.add(c3); 137 columns.add(c4); 138 columns.add(c5); 139 140 assertEquals(columns, t1.getColumns()); 141 } 142 143 146 public void testGetColumn() 147 { 148 assertEquals(t1.getColumn("id"), c1); 149 assertEquals(t1.getColumn("ID"), c1); 150 assertNull(t1.getColumn("not_found")); 151 } 152 153 156 public void testGetName() 157 { 158 assertEquals("users", t1.getName()); 159 } 160 161 164 public void testEquals() 165 { 166 assertTrue(t1.equals(t1)); 167 assertFalse(t1.equals(t2)); 168 assertFalse(t1.equals(t3)); 169 assertTrue(t1.equals(t4)); 170 assertFalse(t1.equals(t5)); 171 assertFalse(t1.equals(t6)); 172 } 173 174 177 public void testEqualsIgnoreType() 178 { 179 assertTrue(t1.equalsIgnoreType(t1)); 180 assertFalse(t1.equalsIgnoreType(t2)); 181 assertFalse(t1.equalsIgnoreType(t3)); 182 assertTrue(t1.equalsIgnoreType(t4)); 183 assertFalse(t1.equalsIgnoreType(t5)); 184 assertFalse(t1.equalsIgnoreType(t6)); 185 } 186 } 187 | Popular Tags |