提交 04bb4fd5 authored 作者: Roy-Breeze's avatar Roy-Breeze

Add more stringent criteria to the UUID conversion handling tests.

上级 7f664523
......@@ -460,18 +460,24 @@ public class TestPreparedStatement extends TestBase {
}
private void testUUIDAsJavaObject(Connection conn) throws SQLException {
String uuidStr = "12345678-1234-4321-8765-123456789012";
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);
UUID origUUID = UUID.fromString(uuidStr);
PreparedStatement prep = conn.prepareStatement("insert into test_uuid values(?)");
prep.setObject(1, origUUID, java.sql.Types.JAVA_OBJECT);
prep.execute();
ResultSet rs = stat.executeQuery("select * from test_uuid");
prep = conn.prepareStatement("select * from test_uuid where id=?");
prep.setObject(1, origUUID);
ResultSet rs = prep.executeQuery();
rs.next();
assertEquals("ffffffff-ffff-fffe-ffff-ffffffffffff", rs.getString(1));
Object o = rs.getObject(1);
assertEquals("java.util.UUID", o.getClass().getName());
assertTrue(o instanceof UUID);
UUID selectedUUID = (UUID) o;
assertTrue(selectedUUID.toString().equals(uuidStr));
assertTrue(selectedUUID.equals(origUUID));
stat.execute("drop table test_uuid");
}
......
......@@ -286,10 +286,12 @@ public class TestValue extends TestBase {
assertEquals("00000000-0000-4000-8000-000000000000", min.getString());
// Test conversion from ValueJavaObject to ValueUuid
ValueJavaObject valObj = ValueJavaObject.getNoCopy(UUID.fromString("12345678-1234-4321-8765-123456789012"), null, null);
UUID origUUID = UUID.fromString("12345678-1234-4321-8765-123456789012");
ValueJavaObject valObj = ValueJavaObject.getNoCopy(origUUID, null, null);
Value valUUID = valObj.convertTo(Value.UUID);
assertTrue(valUUID instanceof ValueUuid);
assertTrue((valUUID.getString().equals("12345678-1234-4321-8765-123456789012")));
assertTrue(valUUID.getObject().equals(origUUID));
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论