1 package uba.db.impl.filesystem;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import uba.db.column.CharColumnSpecification;
7 import uba.db.table.TableSchema;
8 import uba.db.table.TableSchemaBuilder;
9 import uba.db.testhelpers.TestUtils;
10
11 import junit.framework.TestCase;
12
13 /***
14 * @version $Revision: 1.1 $
15 */
16 public class FileSystemTableTest extends TestCase {
17 private File tempDir;
18 private TableSchema tableSchema;
19 private File dataFile;
20 private File schemaFile;
21
22 /***
23 * @see junit.framework.TestCase#setUp()
24 */
25 protected void setUp() throws Exception {
26 super.setUp();
27 tempDir = TestUtils.tempDirectory();
28 tableSchema = new TableSchemaBuilder("test")
29 .addColumn(new CharColumnSpecification("prueba", 20)).build();
30 dataFile = new File(tempDir, tableSchema.tableName()
31 + FileSystemTable.DATA_FILE_SUFFIX);
32 schemaFile = new File(tempDir, tableSchema.tableName()
33 + FileSystemTable.SCHEMA_FILE_SUFFIX);
34 }
35
36 /***
37 * @see junit.framework.TestCase#tearDown()
38 */
39 protected void tearDown() throws Exception {
40 super.tearDown();
41 if (dataFile != null && dataFile.exists()) {
42 dataFile.delete();
43 }
44 if (schemaFile != null && schemaFile.exists()) {
45 schemaFile.delete();
46 }
47 }
48
49 /***
50 * Test: crear una nueva tabla en un directorio.
51 */
52 public void testCreateNew() throws IOException {
53 assertFalse("el archivo " + dataFile + " no debe existir", dataFile.exists());
54 assertFalse("el archivo " + schemaFile + " no debe existir", schemaFile.exists());
55
56 FileSystemTable newTable = FileSystemTable.createNew(tempDir, tableSchema);
57 assertNotNull(newTable);
58
59 assertTrue(dataFile.exists());
60 assertTrue(schemaFile.exists());
61 }
62 }