This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new de79e2f3cde Test cases for oracle xa connection wrapper (#33722)
de79e2f3cde is described below
commit de79e2f3cde74a39a83f4bdef79cfbae8565f4ce
Author: Ansh Singh <[email protected]>
AuthorDate: Thu Nov 21 07:52:26 2024 +0530
Test cases for oracle xa connection wrapper (#33722)
* Written OracleXAConnectionWrapperTest
* Resolved Error while runnings tests
* added convenient way to maintain version of ojdbc
* Removed Unused Imports
* Fixed checkstyle violations
* added LICENSE
---
kernel/transaction/type/xa/core/pom.xml | 10 ++++
.../dialect/OracleXAConnectionWrapperTest.java | 66 ++++++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/kernel/transaction/type/xa/core/pom.xml
b/kernel/transaction/type/xa/core/pom.xml
index 985f26f6561..391c5bc2142 100644
--- a/kernel/transaction/type/xa/core/pom.xml
+++ b/kernel/transaction/type/xa/core/pom.xml
@@ -25,6 +25,9 @@
</parent>
<artifactId>shardingsphere-transaction-xa-core</artifactId>
<name>${project.artifactId}</name>
+ <properties>
+ <ojdbc8.version>23.6.0.24.10</ojdbc8.version>
+ </properties>
<dependencies>
<dependency>
@@ -53,6 +56,13 @@
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.oracle.database.jdbc</groupId>
+ <artifactId>ojdbc8</artifactId>
+ <version>${ojdbc8.version}</version>
+ <scope>test</scope>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
diff --git
a/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
b/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
new file mode 100644
index 00000000000..b2963ce08f1
--- /dev/null
+++
b/kernel/transaction/type/xa/core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/dialect/OracleXAConnectionWrapperTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.xa.jta.connection.dialect;
+
+import oracle.jdbc.internal.OracleConnection;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class OracleXAConnectionWrapperTest {
+
+ private OracleXAConnectionWrapper xaConnectionWrapper;
+
+ @BeforeEach
+ void setUp() {
+ xaConnectionWrapper = new OracleXAConnectionWrapper();
+ xaConnectionWrapper.init(new Properties());
+ }
+
+ @Test
+ void assertWrap() throws SQLException {
+ XADataSource xaDataSource = mock(XADataSource.class);
+ Connection connection = mockConnection();
+ XAConnection actual = xaConnectionWrapper.wrap(xaDataSource,
connection);
+ assertThat(actual, instanceOf(XAConnection.class));
+ }
+
+ @Test
+ void assertGetDatabaseType() {
+ assertThat(xaConnectionWrapper.getDatabaseType(), is("Oracle"));
+ }
+
+ private Connection mockConnection() throws SQLException {
+ Connection mockConnection = mock(Connection.class);
+ when(mockConnection.unwrap(OracleConnection.class))
+ .thenReturn(mock(OracleConnection.class, RETURNS_DEEP_STUBS));
+ return mockConnection;
+ }
+}