提交 7f664523 authored 作者: Roy-Breeze's avatar Roy-Breeze

Add additional unit test coverage to confirm functionality of UUID/JAVA_OBJECT conversion

上级 f03ec003
......@@ -58,6 +58,7 @@ public class TestPreparedStatement extends TestBase {
testExecuteUpdateCall(conn);
testPrepareExecute(conn);
testUUID(conn);
testUUIDAsJavaObject(conn);
testScopedGeneratedKey(conn);
testLobTempFiles(conn);
testExecuteErrorTwice(conn);
......@@ -458,6 +459,22 @@ public class TestPreparedStatement extends TestBase {
stat.execute("drop table test_uuid");
}
private void testUUIDAsJavaObject(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("create table test_uuid(id uuid primary key)");
UUID uuid = new UUID(-2, -1);
PreparedStatement prep = conn.prepareStatement(
"insert into test_uuid values(?)");
prep.setObject(1, uuid, java.sql.Types.JAVA_OBJECT);
prep.execute();
ResultSet rs = stat.executeQuery("select * from test_uuid");
rs.next();
assertEquals("ffffffff-ffff-fffe-ffff-ffffffffffff", rs.getString(1));
Object o = rs.getObject(1);
assertEquals("java.util.UUID", o.getClass().getName());
stat.execute("drop table test_uuid");
}
private void testUUIDGeneratedKeys(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST_UUID(id UUID DEFAULT " +
......
......@@ -286,8 +286,10 @@ public class TestValue extends TestBase {
assertEquals("00000000-0000-4000-8000-000000000000", min.getString());
// Test conversion from ValueJavaObject to ValueUuid
ValueJavaObject vo_uuid = ValueJavaObject.getNoCopy(UUID.randomUUID(), null, null);
assertTrue(vo_uuid.convertTo(Value.UUID) instanceof ValueUuid);
ValueJavaObject valObj = ValueJavaObject.getNoCopy(UUID.fromString("12345678-1234-4321-8765-123456789012"), null, null);
Value valUUID = valObj.convertTo(Value.UUID);
assertTrue(valUUID instanceof ValueUuid);
assertTrue((valUUID.getString().equals("12345678-1234-4321-8765-123456789012")));
ValueJavaObject vo_string = ValueJavaObject.getNoCopy(new String("This is not a ValueUuid object"), null, null);
assertThrows(DbException.class, vo_string).convertTo(Value.UUID);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论