Skip to content

Commit a6c5068

Browse files
authored
Merge pull request #1104 from tsegismont/more_tests
Implement more TCK tests with Oracle Client
2 parents 071f159 + 465eae9 commit a6c5068

File tree

11 files changed

+678
-60
lines changed

11 files changed

+678
-60
lines changed

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/Helper.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import io.vertx.sqlclient.Tuple;
1818
import oracle.sql.TIMESTAMPTZ;
1919

20-
import java.math.BigDecimal;
2120
import java.sql.*;
22-
import java.time.ZoneOffset;
2321
import java.util.ArrayList;
2422
import java.util.List;
2523
import java.util.concurrent.CompletionStage;
@@ -157,23 +155,7 @@ public static Object convertSqlValue(Object value) throws SQLException {
157155
return null;
158156
}
159157

160-
// valid json types are just returned as is
161-
if (value instanceof Boolean || value instanceof String || value instanceof byte[]) {
162-
return value;
163-
}
164-
165-
// numeric values
166-
if (value instanceof Number) {
167-
if (value instanceof BigDecimal) {
168-
BigDecimal d = (BigDecimal) value;
169-
if (d.scale() == 0) {
170-
return ((BigDecimal) value).toBigInteger();
171-
} else {
172-
// we might loose precision here
173-
return ((BigDecimal) value).doubleValue();
174-
}
175-
}
176-
158+
if (value instanceof Boolean || value instanceof String || value instanceof byte[] || value instanceof Number) {
177159
return value;
178160
}
179161

@@ -188,7 +170,7 @@ public static Object convertSqlValue(Object value) throws SQLException {
188170
}
189171

190172
if (value instanceof Timestamp) {
191-
return ((Timestamp) value).toInstant().atOffset(ZoneOffset.UTC);
173+
return ((Timestamp) value).toLocalDateTime();
192174
}
193175

194176
if (value instanceof TIMESTAMPTZ) {

vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleGeneratedKeysTestBase.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.junit.Test;
2929
import org.junit.runner.RunWith;
3030

31-
import java.math.BigInteger;
3231
import java.util.function.Consumer;
3332
import java.util.function.Function;
3433
import java.util.function.Supplier;
@@ -79,15 +78,15 @@ public void shouldRetrieveGeneratedKeyByName(TestContext ctx) {
7978
doTest(ctx, () -> {
8079
return new OraclePrepareOptions()
8180
.setAutoGeneratedKeysIndexes(new JsonArray().add("id"));
82-
}, generated -> verifyGenerated(generated, "ID", BigInteger.class));
81+
}, generated -> verifyGenerated(generated, "ID", Number.class));
8382
}
8483

8584
@Test
8685
public void shouldRetrieveGeneratedKeyByIndex(TestContext ctx) {
8786
doTest(ctx, () -> {
8887
return new OraclePrepareOptions()
8988
.setAutoGeneratedKeysIndexes(new JsonArray().add(1));
90-
}, generated -> verifyGenerated(generated, "ID", BigInteger.class));
89+
}, generated -> verifyGenerated(generated, "ID", Number.class));
9190
}
9291

9392
private void doTest(TestContext ctx, Supplier<OraclePrepareOptions> supplier, Consumer<Row> checks) {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
12+
package io.vertx.oracleclient.test.tck;
13+
14+
import io.vertx.ext.unit.TestContext;
15+
import io.vertx.ext.unit.junit.VertxUnitRunner;
16+
import io.vertx.oracleclient.test.junit.OracleRule;
17+
import io.vertx.sqlclient.tck.BinaryDataTypeDecodeTestBase;
18+
import org.junit.ClassRule;
19+
import org.junit.Ignore;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
23+
import java.math.BigDecimal;
24+
import java.sql.JDBCType;
25+
import java.time.LocalDate;
26+
import java.time.LocalDateTime;
27+
28+
@RunWith(VertxUnitRunner.class)
29+
public class OracleBinaryDataTypeDecodeTest extends BinaryDataTypeDecodeTestBase {
30+
31+
@ClassRule
32+
public static OracleRule rule = OracleRule.SHARED_INSTANCE;
33+
34+
@Override
35+
protected JDBCType getNumericJDBCType() {
36+
return JDBCType.NUMERIC;
37+
}
38+
39+
@Override
40+
protected Class<? extends Number> getNumericClass() {
41+
return BigDecimal.class;
42+
}
43+
44+
@Override
45+
protected Number getNumericValue(Number value) {
46+
return getNumericValue(value.toString());
47+
}
48+
49+
@Override
50+
protected Number getNumericValue(String value) {
51+
return new BigDecimal(value);
52+
}
53+
54+
@Override
55+
protected void initConnector() {
56+
connector = ClientConfig.CONNECT.connect(vertx, rule.options());
57+
}
58+
59+
@Override
60+
public void testSmallInt(TestContext ctx) {
61+
testDecodeGeneric(ctx, "test_int_2", BigDecimal.class, JDBCType.NUMERIC, BigDecimal.valueOf(32767));
62+
}
63+
64+
@Override
65+
public void testInteger(TestContext ctx) {
66+
testDecodeGeneric(ctx, "test_int_4", BigDecimal.class, JDBCType.NUMERIC, BigDecimal.valueOf(2147483647));
67+
}
68+
69+
@Override
70+
public void testBigInt(TestContext ctx) {
71+
testDecodeGeneric(ctx, "test_int_8", BigDecimal.class, JDBCType.NUMERIC, BigDecimal.valueOf(9223372036854775807L));
72+
}
73+
74+
@Override
75+
public void testFloat4(TestContext ctx) {
76+
testDecodeGeneric(ctx, "test_float_4", Double.class, JDBCType.FLOAT, 3.40282e38D);
77+
}
78+
79+
@Test
80+
@Ignore("unsupported")
81+
@Override
82+
public void testDouble(TestContext ctx) {
83+
super.testDouble(ctx);
84+
}
85+
86+
@Test
87+
@Ignore("unsupported")
88+
@Override
89+
public void testBoolean(TestContext ctx) {
90+
super.testBoolean(ctx);
91+
}
92+
93+
@Override
94+
public void testChar(TestContext ctx) {
95+
testDecodeGeneric(ctx, "test_char", String.class, JDBCType.CHAR, "testchar");
96+
}
97+
98+
@Override
99+
public void testDate(TestContext ctx) {
100+
LocalDateTime expected = LocalDate.of(2019, 1, 1).atStartOfDay();
101+
testDecodeGeneric(ctx, "test_date", LocalDate.class, JDBCType.TIMESTAMP, expected);
102+
}
103+
104+
@Test
105+
@Ignore("unsupported")
106+
@Override
107+
public void testTime(TestContext ctx) {
108+
super.testTime(ctx);
109+
}
110+
111+
@Test
112+
@Ignore("unsupported")
113+
@Override
114+
public void testNullValues(TestContext ctx) {
115+
super.testNullValues(ctx);
116+
}
117+
118+
@Test
119+
@Ignore("unsupported")
120+
@Override
121+
public void testSelectAll(TestContext ctx) {
122+
super.testSelectAll(ctx);
123+
}
124+
125+
@Test
126+
@Ignore("unsupported")
127+
@Override
128+
public void testToJsonObject(TestContext ctx) {
129+
super.testToJsonObject(ctx);
130+
}
131+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
12+
package io.vertx.oracleclient.test.tck;
13+
14+
import io.vertx.ext.unit.TestContext;
15+
import io.vertx.ext.unit.junit.VertxUnitRunner;
16+
import io.vertx.oracleclient.test.junit.OracleRule;
17+
import io.vertx.sqlclient.Row;
18+
import io.vertx.sqlclient.Tuple;
19+
import io.vertx.sqlclient.tck.BinaryDataTypeEncodeTestBase;
20+
import org.junit.ClassRule;
21+
import org.junit.Ignore;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
25+
import java.math.BigDecimal;
26+
import java.sql.JDBCType;
27+
import java.time.LocalDate;
28+
import java.time.LocalDateTime;
29+
import java.util.function.BiFunction;
30+
31+
@RunWith(VertxUnitRunner.class)
32+
public class OracleBinaryDataTypeEncodeTest extends BinaryDataTypeEncodeTestBase {
33+
34+
@ClassRule
35+
public static OracleRule rule = OracleRule.SHARED_INSTANCE;
36+
37+
@Override
38+
protected JDBCType getNumericJDBCType() {
39+
return JDBCType.NUMERIC;
40+
}
41+
42+
@Override
43+
protected Class<? extends Number> getNumericClass() {
44+
return BigDecimal.class;
45+
}
46+
47+
@Override
48+
protected Number getNumericValue(Number value) {
49+
return getNumericValue(value.toString());
50+
}
51+
52+
@Override
53+
protected Number getNumericValue(String value) {
54+
return new BigDecimal(value);
55+
}
56+
57+
@Override
58+
protected void initConnector() {
59+
connector = ClientConfig.CONNECT.connect(vertx, rule.options());
60+
}
61+
62+
@Override
63+
protected String statement(String... parts) {
64+
return String.join(" ?", parts);
65+
}
66+
67+
@Override
68+
public void testSmallInt(TestContext ctx) {
69+
testEncodeGeneric(ctx, "test_int_2", BigDecimal.class, null, BigDecimal.valueOf(Short.MIN_VALUE));
70+
}
71+
72+
@Override
73+
public void testInteger(TestContext ctx) {
74+
testEncodeGeneric(ctx, "test_int_4", BigDecimal.class, null, BigDecimal.valueOf(Integer.MIN_VALUE));
75+
}
76+
77+
@Override
78+
public void testBigInt(TestContext ctx) {
79+
testEncodeGeneric(ctx, "test_int_8", BigDecimal.class, null, BigDecimal.valueOf(Long.MIN_VALUE));
80+
}
81+
82+
@Override
83+
public void testFloat4(TestContext ctx) {
84+
testEncodeGeneric(ctx, "test_float_4", Double.class, null, -3.402823e38D);
85+
}
86+
87+
@Test
88+
@Ignore("unsupported")
89+
@Override
90+
public void testDouble(TestContext ctx) {
91+
super.testDouble(ctx);
92+
}
93+
94+
@Override
95+
public void testChar(TestContext ctx) {
96+
super.testChar(ctx);
97+
}
98+
99+
@Override
100+
public void testVarchar(TestContext ctx) {
101+
super.testVarchar(ctx);
102+
}
103+
104+
@Test
105+
@Ignore("unsupported")
106+
@Override
107+
public void testBoolean(TestContext ctx) {
108+
super.testBoolean(ctx);
109+
}
110+
111+
@Override
112+
public void testDate(TestContext ctx) {
113+
LocalDateTime expected = LocalDate.parse("1999-12-31").atStartOfDay();
114+
testEncodeGeneric(ctx, "test_date", LocalDateTime.class, null, expected);
115+
}
116+
117+
@Test
118+
@Ignore("unsupported")
119+
@Override
120+
public void testTime(TestContext ctx) {
121+
super.testTime(ctx);
122+
}
123+
124+
@Test
125+
@Ignore("unsupported")
126+
@Override
127+
public void testNullValues(TestContext ctx) {
128+
super.testNullValues(ctx);
129+
}
130+
131+
protected <T> void testEncodeGeneric(TestContext ctx,
132+
String columnName,
133+
Class<? extends T> clazz,
134+
BiFunction<Row, String, T> getter,
135+
T expected) {
136+
connector.connect(ctx.asyncAssertSuccess(conn -> {
137+
conn
138+
.preparedQuery(statement("UPDATE basicdatatype SET " + columnName + " = ", " WHERE id = 2"))
139+
.execute(Tuple.tuple().addValue(expected), ctx.asyncAssertSuccess(updateResult -> {
140+
conn
141+
.preparedQuery("SELECT " + columnName + " FROM basicdatatype WHERE id = 2")
142+
.execute(ctx.asyncAssertSuccess(result -> {
143+
ctx.assertEquals(1, result.size());
144+
Row row = result.iterator().next();
145+
ctx.assertEquals(1, row.size());
146+
ctx.assertEquals(expected, row.getValue(0));
147+
ctx.assertEquals(expected, row.getValue(columnName));
148+
if (getter != null) {
149+
ctx.assertEquals(expected, getter.apply(row, columnName));
150+
}
151+
// ctx.assertEquals(expected, row.get(clazz, 0));
152+
// ColumnChecker.checkColumn(0, columnName)
153+
// .returns(Tuple::getValue, Row::getValue, expected)
154+
// .returns(byIndexGetter, byNameGetter, expected)
155+
// .forRow(row);
156+
conn.close();
157+
}));
158+
}));
159+
}));
160+
}
161+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
package io.vertx.oracleclient.test.tck;
12+
13+
import io.vertx.ext.unit.junit.VertxUnitRunner;
14+
import io.vertx.oracleclient.test.junit.OracleRule;
15+
import io.vertx.sqlclient.tck.NullValueEncodeTestBase;
16+
import org.junit.ClassRule;
17+
import org.junit.runner.RunWith;
18+
19+
@RunWith(VertxUnitRunner.class)
20+
public class OracleNullValueEncodeTest extends NullValueEncodeTestBase {
21+
22+
@ClassRule
23+
public static OracleRule rule = OracleRule.SHARED_INSTANCE;
24+
25+
@Override
26+
protected void initConnector() {
27+
connector = ClientConfig.POOLED.connect(vertx, rule.options());
28+
}
29+
30+
@Override
31+
protected String statement(String... parts) {
32+
return "SELECT ? FROM dual";
33+
}
34+
}

0 commit comments

Comments
 (0)