~starbuggers/sakila-server/mysql-5.1-wl820

« back to all changes in this revision

Viewing changes to plugin/java_udf/com/mysql/udf/test/util/SimpleResultSetTest.java

  • Committer: Antony T Curtis
  • Date: 2008-04-10 06:09:05 UTC
  • mto: (2542.76.4 mysql-5.1-wl820)
  • mto: This revision was merged to the branch mainline in revision 2772.
  • Revision ID: antony@anubis.xiphis.org-20080410060905-itpom5iyz8ae4dhh
Initial import into Bazaar repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.mysql.udf.test.util;
 
2
 
 
3
import java.sql.ResultSetMetaData;
 
4
import java.sql.SQLException;
 
5
 
 
6
import junit.framework.TestCase;
 
7
 
 
8
import com.mysql.udf.util.SimpleResultSet;
 
9
 
 
10
public class SimpleResultSetTest extends TestCase {
 
11
    public void testOurUsage() throws SQLException {
 
12
        String[] columNames = new String[] { "a", "b", "c" };
 
13
        SimpleResultSet rs = new SimpleResultSet(columNames);
 
14
        rs.addRow(new Object[] { "foo", "bar", "baz" });
 
15
        rs.addRow(new Object[] { "golly", "gee", "whiz" });
 
16
 
 
17
        final ResultSetMetaData metaData = rs.getMetaData();
 
18
        int colcount = metaData.getColumnCount();
 
19
        for (int i = 1; i <= colcount; i++) {
 
20
            String name = metaData.getColumnLabel(i);
 
21
            assertEquals(columNames[i - 1], name);
 
22
            int expectedWidth;
 
23
            switch (i) {
 
24
            case 1:
 
25
                expectedWidth = 5;
 
26
                break;
 
27
            case 2:
 
28
                expectedWidth = 3;
 
29
                break;
 
30
            case 3:
 
31
                expectedWidth = 4;
 
32
                break;
 
33
            default:
 
34
                throw new RuntimeException("?!");
 
35
            }
 
36
            int width = metaData.getColumnDisplaySize(i);
 
37
            assertEquals(expectedWidth, width);
 
38
        }
 
39
 
 
40
        String[][] resultMatrix = new String[2][3];
 
41
 
 
42
        for (int j = 0; rs.next(); j++) {
 
43
            for (int i = 1; i <= colcount; i++) {
 
44
                resultMatrix[j][i - 1] = rs.getString(i);
 
45
            }
 
46
        }
 
47
 
 
48
        assertEquals("foo", resultMatrix[0][0]);
 
49
        assertEquals("bar", resultMatrix[0][1]);
 
50
        assertEquals("baz", resultMatrix[0][2]);
 
51
        assertEquals("golly", resultMatrix[1][0]);
 
52
        assertEquals("gee", resultMatrix[1][1]);
 
53
        assertEquals("whiz", resultMatrix[1][2]);
 
54
    }
 
55
}