Search in sources :

Example 1 with DBInvalidUtil

use of com.microsoft.sqlserver.testframework.DBInvalidUtil in project mssql-jdbc by Microsoft.

the class lobsTest method createLob.

private Object createLob(Class lobClass) {
    // Randomly indicate negative length
    streamLength = ThreadLocalRandom.current().nextInt(3) < 2 ? datasize : -1 - ThreadLocalRandom.current().nextInt(datasize);
    // For streams -1 means any length, avoid to ensure that an exception is always thrown
    if (streamLength == -1 && (lobClass == DBCharacterStream.class || lobClass == DBBinaryStream.class))
        streamLength = datasize;
    log.fine("Length passed into update : " + streamLength);
    byte[] data = new byte[datasize];
    ThreadLocalRandom.current().nextBytes(data);
    if (lobClass == DBCharacterStream.class)
        return new DBInvalidUtil().new InvalidCharacterStream(new String(data), streamLength < -1);
    else if (lobClass == DBBinaryStream.class)
        return new DBInvalidUtil().new InvalidBinaryStream(data, streamLength < -1);
    if (lobClass == Clob.class) {
        ArrayList<SqlType> types = Utils.types();
        SqlType type = Utils.find(String.class);
        Object expected = type.createdata(String.class, data);
        return new DBInvalidUtil().new InvalidClob(expected, false);
    } else {
        ArrayList<SqlType> types = Utils.types();
        SqlType type = Utils.find(byte[].class);
        Object expected = type.createdata(type.getClass(), data);
        return new DBInvalidUtil().new InvalidBlob(expected, false);
    }
}
Also used : DBCharacterStream(com.microsoft.sqlserver.testframework.Utils.DBCharacterStream) DBBinaryStream(com.microsoft.sqlserver.testframework.Utils.DBBinaryStream) SqlType(com.microsoft.sqlserver.testframework.sqlType.SqlType) DBInvalidUtil(com.microsoft.sqlserver.testframework.DBInvalidUtil)

Aggregations

DBInvalidUtil (com.microsoft.sqlserver.testframework.DBInvalidUtil)1 DBBinaryStream (com.microsoft.sqlserver.testframework.Utils.DBBinaryStream)1 DBCharacterStream (com.microsoft.sqlserver.testframework.Utils.DBCharacterStream)1 SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)1