1 package uba.db.table.io;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.DataInputStream;
6 import java.io.DataOutputStream;
7
8 import junit.framework.TestCase;
9 import uba.db.column.CharColumnSpecification;
10 import uba.db.impl.memory.MemoryTable;
11 import uba.db.table.Row;
12 import uba.db.table.TableSchema;
13 import uba.db.table.TableSchemaBuilder;
14
15 /***
16 * Test de unidad {@link uba.db.table.io.RowReader}.
17 *
18 * @version $Revision: 1.2 $
19 */
20 public class RowReaderTest extends TestCase {
21 private RowReader reader;
22 private Row expectedRowOne;
23 private Row expectedRowTwo;
24
25 /***
26 * @see junit.framework.TestCase#setUp()
27 */
28 protected void setUp() throws Exception {
29 super.setUp();
30 CharColumnSpecification colA = new CharColumnSpecification("a", 10);
31 CharColumnSpecification colB = new CharColumnSpecification("b", 5);
32 TableSchema schema = new TableSchemaBuilder("prueba").addColumn(colA).addColumn(colB).build();
33 MemoryTable table = new MemoryTable(schema);
34 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
35 DataOutputStream out = new DataOutputStream(byteArrayOutputStream);
36 RowWriter writer = new RowWriter(table, out);
37 expectedRowOne = new Row(table, new Object[] { "hola", "mundo" });
38 writer.write(expectedRowOne);
39 expectedRowTwo = new Row(table, new Object[] { "jian", "carlo" });
40 writer.write(expectedRowTwo);
41
42 byte[] outputArray = byteArrayOutputStream.toByteArray();
43 reader = new RowReader(table, new DataInputStream(new ByteArrayInputStream(outputArray)));
44 }
45
46 /***
47 * Test: leer los valores de una fila.
48 */
49 public void testWrite() throws Exception {
50 Row result = reader.read();
51 assertEquals(expectedRowOne, result);
52
53 result = reader.read();
54 assertEquals(expectedRowTwo, result);
55 }
56 }