1   package uba.db.impl.memory;
2   
3   import java.util.List;
4   
5   import junit.framework.TestCase;
6   import uba.db.column.Column;
7   import uba.db.column.ColumnSpecification;
8   import uba.db.column.IntegerColumnSpecification;
9   import uba.db.table.Table;
10  import uba.db.table.TableSchema;
11  import uba.db.table.TableSchemaBuilder;
12  
13  /***
14   * Test de unidad para {@link MemoryTable}.
15   * 
16   * @version $Revision: 1.1 $
17   */
18  public class MemoryTableTest extends TestCase {
19      /***
20       * Test: Crear una tabla.
21       */
22      public void testCreate() throws Exception {
23          TableSchema tableSchema = new TableSchemaBuilder("test")
24                  .addColumn(new IntegerColumnSpecification("a"))
25                  .addColumn(new IntegerColumnSpecification("b")).build();
26          Table table = new MemoryTable(tableSchema);
27  
28          // la tabla debe tener el nombre especificado
29          assertEquals(tableSchema.tableName(), table.name());
30  
31          // la tabla debe tener las columnas especificadas
32          int ncolumns = table.columns().size();
33          List columnSpecifications = tableSchema.columnSpecifications();
34          assertEquals(columnSpecifications.size(), ncolumns);
35          for (int i = 0; i < ncolumns; i++) {
36              ColumnSpecification colSpec = (ColumnSpecification) columnSpecifications.get(i);
37              Column col = (Column) table.columns().get(i);
38              
39              assertEquals(colSpec.name(), col.name());
40              assertEquals(colSpec.constraint(), col.constraint());
41              assertEquals(colSpec.dataTypeDisplayString(), col.dataTypeDisplayString());
42              assertEquals(table, col.table());
43          }
44      }
45  }