Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package openjproxy.jdbc;

import openjproxy.jdbc.testutil.TestDBUtils;
import openjproxy.jdbc.testutil.TestDBUtils.ConnectionResult;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
Expand All @@ -8,7 +10,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -31,11 +32,12 @@ static void setup() {
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void createAndReadingBinaryStreamSuccessful(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void createAndReadingBinaryStreamSuccessful(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException, ClassNotFoundException, IOException {
assumeFalse(isTestDisabled, "Skipping Oracle tests");

Connection conn = DriverManager.getConnection(url, user, pwd);
ConnectionResult connResult = TestDBUtils.createConnection(url, user, pwd, isXA);
Connection conn = connResult.getConnection();

System.out.println("Testing Oracle binary stream for url -> " + url);

Expand All @@ -51,7 +53,11 @@ void createAndReadingBinaryStreamSuccessful(String driverClass, String url, Stri
" val_raw2 RAW(2000)" +
")");

conn.setAutoCommit(false);
connResult.startXATransactionIfNeeded();

if (!isXA) {
conn.setAutoCommit(false);
}

PreparedStatement psInsert = conn.prepareStatement(
"insert into oracle_binary_stream_test (val_raw1, val_raw2) values (?, ?)"
Expand All @@ -65,7 +71,8 @@ void createAndReadingBinaryStreamSuccessful(String driverClass, String url, Stri
psInsert.setBinaryStream(2, inputStream2, 7);
psInsert.executeUpdate();

conn.commit();
connResult.commit();
connResult.startXATransactionIfNeeded();

PreparedStatement psSelect = conn.prepareStatement("select val_raw1, val_raw2 from oracle_binary_stream_test ");
ResultSet resultSet = psSelect.executeQuery();
Expand All @@ -88,15 +95,16 @@ void createAndReadingBinaryStreamSuccessful(String driverClass, String url, Stri

resultSet.close();
psSelect.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url, String user, String pwd) throws SQLException, IOException {
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException, IOException {
assumeFalse(isTestDisabled, "Skipping Oracle tests");

Connection conn = DriverManager.getConnection(url, user, pwd);
ConnectionResult connResult = TestDBUtils.createConnection(url, user, pwd, isXA);
Connection conn = connResult.getConnection();

System.out.println("Testing Oracle large binary stream for url -> " + url);

Expand All @@ -111,6 +119,8 @@ void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url,
" val_blob BLOB" +
")");

connResult.startXATransactionIfNeeded();

PreparedStatement psInsert = conn.prepareStatement(
"insert into oracle_large_binary_test (val_blob) values (?)"
);
Expand All @@ -119,6 +129,8 @@ void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url,
psInsert.setBinaryStream(1, inputStream);

psInsert.executeUpdate();
connResult.commit();
connResult.startXATransactionIfNeeded();

PreparedStatement psSelect = conn.prepareStatement("select val_blob from oracle_large_binary_test ");
ResultSet resultSet = psSelect.executeQuery();
Expand All @@ -138,15 +150,16 @@ void createAndReadingLargeBinaryStreamSuccessful(String driverClass, String url,

resultSet.close();
psSelect.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleSpecificBinaryHandling(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleSpecificBinaryHandling(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException, ClassNotFoundException, IOException {
assumeFalse(isTestDisabled, "Skipping Oracle tests");

Connection conn = DriverManager.getConnection(url, user, pwd);
ConnectionResult connResult = TestDBUtils.createConnection(url, user, pwd, isXA);
Connection conn = connResult.getConnection();

System.out.println("Testing Oracle-specific binary handling for url -> " + url);

Expand All @@ -163,6 +176,8 @@ void testOracleSpecificBinaryHandling(String driverClass, String url, String use
" large_blob BLOB" +
")");

connResult.startXATransactionIfNeeded();

PreparedStatement psInsert = conn.prepareStatement(
"insert into oracle_binary_types_test (small_raw, medium_raw, large_blob) values (?, ?, ?)"
);
Expand All @@ -177,6 +192,8 @@ void testOracleSpecificBinaryHandling(String driverClass, String url, String use
psInsert.setBinaryStream(3, new ByteArrayInputStream(largeData.getBytes()));

psInsert.executeUpdate();
connResult.commit();
connResult.startXATransactionIfNeeded();

PreparedStatement psSelect = conn.prepareStatement("select small_raw, medium_raw, large_blob from oracle_binary_types_test");
ResultSet resultSet = psSelect.executeQuery();
Expand All @@ -198,6 +215,6 @@ void testOracleSpecificBinaryHandling(String driverClass, String url, String use

resultSet.close();
psSelect.close();
conn.close();
connResult.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package openjproxy.jdbc;

import openjproxy.jdbc.testutil.TestDBUtils;
import openjproxy.jdbc.testutil.TestDBUtils.ConnectionResult;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -33,17 +32,19 @@ class OracleBlobIntegrationTest {
private static boolean isTestDisabled;
private String tableName;
private Connection conn;
private ConnectionResult connResult;

@BeforeAll
static void checkTestConfiguration() {
isTestDisabled = !Boolean.parseBoolean(System.getProperty("enableOracleTests", "false"));
}

void setUp(String driverClass, String url, String user, String pwd) throws SQLException {
void setUp(String url, String user, String pwd, boolean isXA) throws SQLException {
assumeFalse(isTestDisabled, "Oracle tests are disabled");

this.tableName = "oracle_blob_test";
conn = DriverManager.getConnection(url, user, pwd);
connResult = TestDBUtils.createConnection(url, user, pwd, isXA);
conn = connResult.getConnection();

try {
executeUpdate(conn, "DROP TABLE " + tableName);
Expand All @@ -58,11 +59,11 @@ void setUp(String driverClass, String url, String user, String pwd) throws SQLEx
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleBlobCreationAndRetrieval(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
setUp(driverClass, url, user, pwd);
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleBlobCreationAndRetrieval(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException {
setUp(url, user, pwd, isXA);

System.out.println("Testing Oracle BLOB creation and retrieval for url -> " + url);
System.out.println("Testing Oracle BLOB creation and retrieval for driver -> " + driverClass + ", url -> " + url);

String testData = "Oracle BLOB test data - special characters: äöü ñ 中文 🚀";
byte[] dataBytes = testData.getBytes(StandardCharsets.UTF_8);
Expand Down Expand Up @@ -96,15 +97,15 @@ void testOracleBlobCreationAndRetrieval(String driverClass, String url, String u
psInsert.close();
psSelect.close();
rs.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleLargeBlobHandling(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
setUp(driverClass, url, user, pwd);
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleLargeBlobHandling(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException {
setUp(url, user, pwd, isXA);

System.out.println("Testing Oracle large BLOB handling for url -> " + url);
System.out.println("Testing Oracle large BLOB handling for driver -> " + driverClass + ", url -> " + url);

// Create a large test string (1MB)
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -144,15 +145,15 @@ void testOracleLargeBlobHandling(String driverClass, String url, String user, St
psInsert.close();
psSelect.close();
rs.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleBlobBinaryStream(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
setUp(driverClass, url, user, pwd);
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleBlobBinaryStream(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException {
setUp(url, user, pwd, isXA);

System.out.println("Testing Oracle BLOB binary stream for url -> " + url);
System.out.println("Testing Oracle BLOB binary stream for driver -> " + driverClass + ", url -> " + url);

// Test with binary data (not just text)
byte[] binaryData = new byte[1000];
Expand All @@ -177,10 +178,8 @@ void testOracleBlobBinaryStream(String driverClass, String url, String user, Str

assertTrue(rs.next());

InputStream binaryStream = rs.getBinaryStream(1);
assertNotNull(binaryStream);

byte[] retrievedData = binaryStream.readAllBytes();
byte[] retrievedData = rs.getBytes(1);
assertNotNull(retrievedData);
assertEquals(binaryData.length, retrievedData.length);

// Verify each byte
Expand All @@ -192,16 +191,15 @@ void testOracleBlobBinaryStream(String driverClass, String url, String user, Str
psInsert.close();
psSelect.close();
rs.close();
binaryStream.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleBlobUpdate(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
setUp(driverClass, url, user, pwd);
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleBlobUpdate(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException{
setUp(url, user, pwd, isXA);

System.out.println("Testing Oracle BLOB update for url -> " + url);
System.out.println("Testing Oracle BLOB update for driver -> " + driverClass + ", url -> " + url);

String originalData = "Original Oracle BLOB data";
String updatedData = "Updated Oracle BLOB data with more content";
Expand Down Expand Up @@ -240,15 +238,15 @@ void testOracleBlobUpdate(String driverClass, String url, String user, String pw
psUpdate.close();
psSelect.close();
rs.close();
conn.close();
connResult.close();
}

@ParameterizedTest
@CsvFileSource(resources = "/oracle_connections.csv")
void testOracleEmptyAndNullBlob(String driverClass, String url, String user, String pwd) throws SQLException, ClassNotFoundException, IOException {
setUp(driverClass, url, user, pwd);
@CsvFileSource(resources = "/oracle_connections_xa_modes.csv")
void testOracleEmptyAndNullBlob(String driverClass, String url, String user, String pwd, boolean isXA) throws SQLException {
setUp(url, user, pwd, isXA);

System.out.println("Testing Oracle empty and null BLOB for url -> " + url);
System.out.println("Testing Oracle empty and null BLOB for driver -> " + driverClass + ", url -> " + url);

// Insert empty BLOB
PreparedStatement psInsert = conn.prepareStatement(
Expand Down Expand Up @@ -284,6 +282,6 @@ void testOracleEmptyAndNullBlob(String driverClass, String url, String user, Str
psInsert.close();
psSelect.close();
rs.close();
conn.close();
connResult.close();
}
}
Loading
Loading