Skip to content

Commit 5cd6b67

Browse files
committed
Adapt tests for new H2 API
H2 has a new default column length H2 classes ValueInt and RowImpl were renamed
1 parent 160445a commit 5cd6b67

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<checkstyle.version>9.0.1</checkstyle.version>
2929
<docbkx-maven-plugin.version>2.0.17</docbkx-maven-plugin.version>
3030
<forbiddenapis.version>3.2</forbiddenapis.version>
31-
<h2.version>2.0.206</h2.version>
31+
<h2.version>2.1.210</h2.version>
3232
<hamcrest.version>2.2</hamcrest.version>
3333
<hsqldb.version>2.5.0</hsqldb.version>
3434
<jline.version>3.21.0</jline.version>

src/test/java/sqlline/BufferedRowsTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import java.nio.charset.StandardCharsets;
2020
import java.util.stream.Stream;
2121

22+
import org.h2.result.DefaultRow;
2223
import org.h2.tools.SimpleResultSet;
24+
import org.h2.value.Value;
25+
import org.h2.value.ValueInteger;
2326
import org.junit.jupiter.api.Assertions;
2427
import org.junit.jupiter.params.ParameterizedTest;
2528
import org.junit.jupiter.params.provider.Arguments;
@@ -39,7 +42,9 @@ public void nextListTest(int buffer, int size) {
3942
try {
4043
SimpleResultSet rs = new SimpleResultSet();
4144
for (int i = 0; i < size; i++) {
42-
rs.addRow(1, 2);
45+
rs.addRow(
46+
new DefaultRow(
47+
new Value[] {ValueInteger.get(1), ValueInteger.get(2)}, 123));
4348
}
4449

4550
SqlLine sqlLine = getSqlLine();

src/test/java/sqlline/SqlLineArgsTest.java

+31-23
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public void testMultilineScriptWithH2Comments() {
370370
final String script = "\n"
371371
+ "\n"
372372
+ "!set incremental true\n"
373+
+ "!set maxColumnWidth 10\n"
373374
+ "\n"
374375
+ "\n"
375376
+ "select * from information_schema.tables// ';\n"
@@ -388,8 +389,8 @@ public void testMultilineScriptWithH2Comments() {
388389
"--run=" + tmpHistoryFile.getAbsolutePath());
389390
assertThat(status, equalTo(SqlLine.Status.OK));
390391
String output = os.toString("UTF8");
391-
final String expected = "| TABLE_CATALOG | TABLE_SCHEMA |"
392-
+ " TABLE_NAME | TABLE_TYPE | STORAGE_TYPE | SQL |";
392+
final String expected = "| UNNAMED |"
393+
+ " INFORMATION_SCHEMA | ENUM_VALUES | BASE TABLE";
393394
assertThat(output, containsString(expected));
394395
sqlLine.runCommands(new DispatchCallback(), "!quit");
395396
assertTrue(sqlLine.isExit());
@@ -1593,14 +1594,15 @@ String readPassword(String url) {
15931594
DispatchCallback dc = new DispatchCallback();
15941595
sqlLine.runCommands(dc,
15951596
"!set maxwidth 80",
1597+
"!set maxColumnWidth 10",
15961598
"!set incremental true");
15971599
sqlLine.runCommands(dc, "!connect "
15981600
+ ConnectionSpec.H2.url + " "
15991601
+ ConnectionSpec.H2.username);
16001602
sqlLine.runCommands(dc, "!tables");
16011603
String output = os.toString("UTF8");
1602-
final String expected = "| TABLE_CAT | TABLE_SCHEM | "
1603-
+ "TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |";
1604+
final String expected = "| TABLE_CAT | TABLE_SCHEM |"
1605+
+ " TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT |";
16041606
assertThat(output, containsString(expected));
16051607
sqlLine.runCommands(new DispatchCallback(), "!quit");
16061608
assertTrue(sqlLine.isExit());
@@ -1627,6 +1629,7 @@ public void testConnectWithDbPropertyAsParameter() {
16271629
DispatchCallback dc = new DispatchCallback();
16281630
sqlLine.runCommands(dc,
16291631
"!set maxwidth 80",
1632+
"!set maxColumnWidth 10\n",
16301633
"!set incremental true");
16311634
String fakeNonEmptyPassword = "nonEmptyPasswd";
16321635
final byte[] bytes =
@@ -1638,8 +1641,8 @@ public void testConnectWithDbPropertyAsParameter() {
16381641
+ StringUtils.convertBytesToHex(bytes));
16391642
sqlLine.runCommands(dc, "!tables");
16401643
String output = os.toString("UTF8");
1641-
final String expected = "| TABLE_CAT | TABLE_SCHEM | "
1642-
+ "TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |";
1644+
final String expected = "| TABLE_CAT | TABLE_SCHEM |"
1645+
+ " TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT |";
16431646
assertThat(output, containsString(expected));
16441647
sqlLine.runCommands(new DispatchCallback(), "!quit");
16451648
assertTrue(sqlLine.isExit());
@@ -1703,7 +1706,7 @@ public void testConnectWithDbProperty() {
17031706
DispatchCallback dc = new DispatchCallback();
17041707

17051708
try {
1706-
sqlLine.runCommands(dc, "!set maxwidth 80");
1709+
sqlLine.runCommands(dc, "!set maxwidth 80", "!set maxColumnWidth 10");
17071710

17081711
// fail attempt
17091712
String fakeNonEmptyPassword = "nonEmptyPasswd";
@@ -1729,8 +1732,8 @@ public void testConnectWithDbProperty() {
17291732
sqlLine.runCommands(dc, "!set incremental true");
17301733
sqlLine.runCommands(dc, "!tables");
17311734
output = os.toString("UTF8");
1732-
final String expected1 = "| TABLE_CAT | TABLE_SCHEM | "
1733-
+ "TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |";
1735+
final String expected1 = "| TABLE_CAT | TABLE_SCHEM |"
1736+
+ " TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT |";
17341737
assertThat(output, containsString(expected1));
17351738

17361739
sqlLine.runCommands(dc, "select 5;");
@@ -1864,10 +1867,11 @@ public void testTablesH2() {
18641867
// Set width so we don't inherit from the current terminal.
18651868
final String script = "!set maxwidth 80\n"
18661869
+ "!set incremental true\n"
1870+
+ "!set maxColumnWidth 10\n"
18671871
+ "!tables\n";
1868-
final String line0 = "| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |";
1872+
final String line0 = "| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |";
18691873
final String line1 =
1870-
"| UNNAMED | INFORMATION_SCHEMA | CATALOGS | SYSTEM TABLE";
1874+
"| UNNAMED | INFORMATION_SCHEMA | CONSTANTS | BASE TABLE";
18711875
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
18721876
allOf(containsString(line0), containsString(line1)));
18731877
}
@@ -1878,11 +1882,12 @@ public void testTablesWithTablePattern() {
18781882
// Set width so we don't inherit from the current terminal.
18791883
final String script = "!set maxwidth 80\n"
18801884
+ "!set incremental true\n"
1881-
+ "!tables CATALO%\n";
1885+
+ "!set maxColumnWidth 10\n"
1886+
+ "!tables INDEXES%\n";
18821887
final String line0 =
1883-
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |\n";
1888+
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT |\n";
18841889
final String line1 =
1885-
"| UNNAMED | INFORMATION_SCHEMA | CATALOGS | SYSTEM TABLE | | |\n";
1890+
"| UNNAMED | INFORMATION_SCHEMA | INDEXES | BASE TABLE | | |\n";
18861891
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
18871892
allOf(containsString(line0), containsString(line1)));
18881893
}
@@ -1893,11 +1898,12 @@ public void testTablesWithSchemaTableType() {
18931898
// Set width so we don't inherit from the current terminal.
18941899
final String script = "!set maxwidth 80\n"
18951900
+ "!set incremental true\n"
1896-
+ "!tables INFORMATION_% CAT% \"SYSTEM TABLE\"\n";
1901+
+ "!set maxColumnWidth 10\n"
1902+
+ "!tables INFORMATION_% \n";
18971903
final String line0 =
1898-
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |\n";
1904+
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT |\n";
18991905
final String line1 =
1900-
"| UNNAMED | INFORMATION_SCHEMA | CATALOGS | SYSTEM TABLE | | |\n";
1906+
"| UNNAMED | INFORMATION_SCHEMA | INFORMATION_SCHEMA_CATALOG_NAME | BASE TAB |\n";
19011907
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
19021908
allOf(containsString(line0), containsString(line1)));
19031909
}
@@ -1907,12 +1913,13 @@ public void testColumnsWithSchemaTableType() {
19071913
connectionSpec = ConnectionSpec.H2;
19081914
// Set width so we don't inherit from the current terminal.
19091915
final String script = "!set maxwidth 80\n"
1916+
+ "!set maxColumnWidth 10\n"
19101917
+ "!set incremental true\n"
1911-
+ "!columns INFORMATION% CAT% CAT%\n";
1918+
+ "!columns INFORMATION_SCHEMA % %\n";
19121919
final String line0 =
1913-
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME |\n";
1920+
"| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME |\n";
19141921
final String line1 =
1915-
"| UNNAMED | INFORMATION_SCHEMA | CATALOGS | CATALOG_NAME | 12 | V |\n";
1922+
"| UNNAMED | INFORMATION_SCHEMA | CHECK_CONSTRAINTS | CONSTRAINT_CATALOG | 1 |\n";
19161923
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
19171924
allOf(containsString(line0), containsString(line1)));
19181925
}
@@ -1942,10 +1949,11 @@ public void testTablesH2WithErrorDriver() {
19421949
// Set width so we don't inherit from the current terminal.
19431950
final String script = "!set maxwidth 80\n"
19441951
+ "!set incremental true\n"
1952+
+ "!set maxColumnWidth 10\n"
19451953
+ "!tables\n";
1946-
final String line0 = "| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |";
1954+
final String line0 = "| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |";
19471955
final String line1 =
1948-
"| UNNAMED | INFORMATION_SCHEMA | CATALOGS | SYSTEM TABLE";
1956+
"| UNNAMED | INFORMATION_SCHEMA | CONSTANTS | BASE TABLE";
19491957
final String message = "Could not find driver "
19501958
+ connectionSpec.driver
19511959
+ "; using registered driver org.h2.Driver instead";
@@ -2338,7 +2346,7 @@ public List<String> allowedDrivers() {
23382346
+ " sqlline.extensions.CustomApplication\n"
23392347
+ "!scan";
23402348
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
2341-
allOf(containsString("yes 1.4 org.h2.Driver"),
2349+
allOf(containsString("yes 2.1 org.h2.Driver"),
23422350
not(containsString("org.hsqldb.jdbc.JDBCDriver"))));
23432351
}
23442352

src/test/java/sqlline/SqlLineHighlighterTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ public void testH2SqlKeywordsFromDatabase() {
553553
"GROUPS",
554554
"IF",
555555
"ILIKE",
556-
"INTERSECTS",
557556
"LIMIT",
558557
"MINUS",
559558
"OFFSET",

0 commit comments

Comments
 (0)