public void testSetSqlValueWithSomethingThatLooksLikeUuidButIsNot() throws Exception { final MockPreparedStatement preparedStatement = new MockPreparedStatement(); final String[] given = { "2aad615a-d8e1-11e2-b8ed-50e549c9b654", "uuid'2aad615a-d8e1-11e2-b8ed-50e549c9b65'" }; final Object[] expected = {null, null}; final int[] expectedSqlTypesForDataType = {Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY}; for (int i = 0; i < expected.length; i++) { final String givenValue = given[i]; final Object expectedValue = expected[i]; for (int j = 0; j < TYPES.length; j++) { final DataType dataType = TYPES[j]; final int expectedSqlType = expectedSqlTypesForDataType[j]; dataType.setSqlValue(givenValue, 1, preparedStatement); assertEquals( "Loop " + i + " Type " + dataType, 1, preparedStatement.getLastSetObjectParamIndex()); assertEquals( "Loop " + i + " Type " + dataType, expectedSqlType, preparedStatement.getLastSetObjectTargetSqlType()); final Object actualValue = preparedStatement.getLastSetObjectParamValue(); assertEquals("Loop " + i + " Type " + dataType, expectedValue, actualValue); } } }
public void testSetSqlValueWithUuid() throws Exception { final MockPreparedStatement preparedStatement = new MockPreparedStatement(); final String[] given = {"uuid'2aad615a-d8e1-11e2-b8ed-50e549c9b654'"}; final byte[][] expected = { new byte[] { (byte) 0x2a, (byte) 0xad, (byte) 0x61, (byte) 0x5a, (byte) 0xd8, (byte) 0xe1, (byte) 0x11, (byte) 0xe2, (byte) 0xb8, (byte) 0xed, (byte) 0x50, (byte) 0xe5, (byte) 0x49, (byte) 0xc9, (byte) 0xb6, (byte) 0x54 } }; final int[] expectedSqlTypesForDataType = {Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY}; for (int i = 0; i < expected.length; i++) { final String givenValue = given[i]; final byte[] expectedValue = expected[i]; for (int j = 0; j < TYPES.length; j++) { final DataType dataType = TYPES[j]; final int expectedSqlType = expectedSqlTypesForDataType[j]; dataType.setSqlValue(givenValue, 1, preparedStatement); assertEquals( "Loop " + i + " Type " + dataType, 1, preparedStatement.getLastSetObjectParamIndex()); assertEquals( "Loop " + i + " Type " + dataType, expectedSqlType, preparedStatement.getLastSetObjectTargetSqlType()); final byte[] actualValue = (byte[]) preparedStatement.getLastSetObjectParamValue(); assertTrue("Loop " + i + " Type " + dataType, Arrays.equals(expectedValue, actualValue)); } } }