|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +package org.elasticsearch.xpack.sql.jdbc; |
| 8 | + |
| 9 | +import org.elasticsearch.test.ESTestCase; |
| 10 | + |
| 11 | +import java.sql.ResultSetMetaData; |
| 12 | +import java.sql.SQLException; |
| 13 | +import java.util.Arrays; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +import static org.elasticsearch.xpack.sql.client.StringUtils.EMPTY; |
| 17 | + |
| 18 | +public class JdbcResultSetMetaDataTests extends ESTestCase { |
| 19 | + |
| 20 | + private final List<JdbcColumnInfo> columns = Arrays.asList( |
| 21 | + new JdbcColumnInfo("test_keyword", EsType.KEYWORD, EMPTY, EMPTY, EMPTY, EMPTY, 0), |
| 22 | + new JdbcColumnInfo("test_integer", EsType.INTEGER, EMPTY, EMPTY, EMPTY, EMPTY, 11), |
| 23 | + new JdbcColumnInfo("test_double", EsType.DOUBLE, EMPTY, EMPTY, EMPTY, EMPTY, 25), |
| 24 | + new JdbcColumnInfo("test_long", EsType.LONG, "test_table", "test", "schema", "custom_label", 20) |
| 25 | + ); |
| 26 | + private final JdbcResultSetMetaData metaData = new JdbcResultSetMetaData(null, columns); |
| 27 | + |
| 28 | + public void testColumnsProperties() throws SQLException { |
| 29 | + int maxColumnIndex = columns.size(); |
| 30 | + assertEquals(false, metaData.isAutoIncrement(randomIntBetween(1, maxColumnIndex))); |
| 31 | + assertEquals(true, metaData.isCaseSensitive(randomIntBetween(1, maxColumnIndex))); |
| 32 | + assertEquals(true, metaData.isSearchable(randomIntBetween(1, maxColumnIndex))); |
| 33 | + assertEquals(false, metaData.isCurrency(randomIntBetween(1, maxColumnIndex))); |
| 34 | + assertEquals(ResultSetMetaData.columnNullableUnknown, metaData.isNullable(randomIntBetween(1, maxColumnIndex))); |
| 35 | + assertEquals(false, metaData.isSigned(1)); |
| 36 | + assertEquals(true, metaData.isSigned(2)); |
| 37 | + assertEquals(true, metaData.isSigned(3)); |
| 38 | + assertEquals(true, metaData.isSigned(4)); |
| 39 | + } |
| 40 | + |
| 41 | + public void testColumnNamesAndLabels() throws SQLException { |
| 42 | + assertEquals("test_keyword", metaData.getColumnName(1)); |
| 43 | + assertEquals("test_integer", metaData.getColumnName(2)); |
| 44 | + assertEquals("test_double", metaData.getColumnName(3)); |
| 45 | + assertEquals("test_long", metaData.getColumnName(4)); |
| 46 | + |
| 47 | + assertEquals("test_keyword", metaData.getColumnLabel(1)); |
| 48 | + assertEquals("test_integer", metaData.getColumnLabel(2)); |
| 49 | + assertEquals("test_double", metaData.getColumnLabel(3)); |
| 50 | + assertEquals("custom_label", metaData.getColumnLabel(4)); |
| 51 | + } |
| 52 | +} |
0 commit comments