You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/08/15 01:46:13 UTC
(shardingsphere) branch master updated: Add tests for Firebird Proxy (#36205)
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 055b41e78ec Add tests for Firebird Proxy (#36205)
055b41e78ec is described below
commit 055b41e78ec09c80f57ec43115856508a6766d62
Author: Maxim Sentyabrskiy <16...@users.noreply.github.com>
AuthorDate: Fri Aug 15 04:46:06 2025 +0300
Add tests for Firebird Proxy (#36205)
* RS-242326. fix for deadlock while transaction execution
* RS-242327. remove unused payload field
* RS-242327. move records processing to separate function
* RS-242327. refactor FirebirdSQLInfoReturnValue
* RS-242327. remove unused payload in getLength
* RS-242327. remove readParameters
* RS-242327. remove unused payload in getLength
* RS-242327. remove unused getSelectedTableNames method
* RS-242327. refactor Optional<IdentifierValue> to IdentifierValue
* RS-242327. replace FirebirdCommandPacket with CommandPacket
* RS-242327. rename salt variable
* RS-243966. fix incorrect index in fetch response packet
* RS-243966. add null check in writeString function
* RS-243966. fix for incorrect buffer allocations
* RS-243966. revert back changes in FirebirdPacketCodecEngine
* RS-241306. add test coverage for all Firebird protocol enum classes
* RS-241306. complete implementation of FirebirdPacketCodecEngine
* RS-241306. add missing unit test for FirebirdConnectionProtocolVersion
* spotless fix for FirebirdPacketCodecEngineTest
* RS-241306. add tests for Firebird generic packets in protocol module
* RS-241306. add tests for Firebird handshake packets in protocol module
* correct expected buffer length in FirebirdPacketPayload test
* RS-241306. add test for FirebirdInfoPacket
* RS-241306. add test for FirebirdUnsupportedCommandPacket
* RS-241306. add unit tests for Firebird transaction command packets
* RS-241306. add unit tests for Firebird statement packets
* RS-241306. add unit tests for FirebirdCommandPacketFactory and refactor FirebirdFetchStatementPacketTest
* RS-241306. add unit tests for Firebird execute statement
* spotless and checkstyle fix
* RS-241306. add missing unit tests
* RS-241306. add unit tests for Firebird Prepare Statement
* RS-241307. add unit tests for FirebirdUnsupportedCommandExecutor
* RS-241307. add unit tests for SRP and Legacy Auth
* RS-241307. add unit tests for SQL and Database Info Executors
* RS-241307. add unit tests for Firebird Allocate, Free, and Fetch statement command executors
* RS-241307. add unit tests for Firebird transaction command executors
* RS-241307. add unit tests for FirebirdExecuteStatementCommandExecutor
* RS-241307. add unit test for FirebirdCommandExecuteEngine
* RS-241307. add unit test for FirebirdAuthenticationEngine
* spotless and checkstyle fix
* RS-241307. add unit test for FirebirdPrepareStatementCommand
* resolve conflicts
* refactoring
* spotless and checkstyle fix
* correct method name in FirebirdConnectionProtocolVersion
* add methods for truncated Firebird packet decoding
* spotless fix
* fix naming in tests
* fix build tests
* replaced Unpooled with mocked ByteBuf
* replaced Unpooled with mocked ByteBuf
* move common mock initialization to class fields
* move common mock initialization to class fields
---------
Co-authored-by: timofey.saharovskiy <ti...@red-soft.ru>
Co-authored-by: TedCraft <te...@yandex.ru>
---
.../FirebirdConnectionProtocolVersion.java | 4 +-
.../codec/FirebirdPacketCodecEngineTest.java | 168 +++++++++++++++++++-
.../constant/FirebirdAuthenticationMethodTest.java | 42 +++++
...FirebirdProtocolDefaultVersionProviderTest.java | 2 +-
.../FirebirdParameterBufferTypeTest.java} | 14 +-
.../FirebirdConnectionProtocolVersionTest.java | 49 ++++++
.../command/FirebirdCommandPacketFactoryTest.java | 125 +++++++++++++++
.../command/FirebirdCommandPacketTypeTest.java} | 14 +-
.../FirebirdUnsupportedCommandPacketTest.java} | 25 +--
.../query/FirebirdBinaryColumnTypeTest.java | 101 ++++++++++++
.../command/query/info/FirebirdInfoPacketTest.java | 64 ++++++++
.../query/info/FirebirdInfoPacketTypeTest.java} | 24 +--
.../common/FirebirdCommonInfoPacketTypeTest.java | 59 +++++++
.../FirebirdDatabaseInfoPacketTypeTest.java} | 14 +-
.../FirebirdDatabaseInfoReturnPacketTest.java | 92 +++++++++++
.../type/sql/FirebirdSQLInfoPacketTypeTest.java} | 14 +-
.../type/sql/FirebirdSQLInfoReturnPacketTest.java | 66 ++++++++
.../type/sql/FirebirdSQLInfoReturnValueTest.java} | 11 +-
.../FirebirdAllocateStatementPacketTest.java} | 26 +++-
.../FirebirdFetchStatementPacketTest.java | 67 ++++++++
.../statement/FirebirdFreeStatementPacketTest.java | 50 ++++++
.../FirebirdExecuteStatementPacketTest.java | 106 +++++++++++++
.../FirebirdBinaryProtocolValueFactoryTest.java | 117 ++++++++++++++
.../FirebirdByteBinaryProtocolValueTest.java | 59 +++++++
.../FirebirdDateBinaryProtocolValueTest.java | 55 +++++++
.../FirebirdDoubleBinaryProtocolValueTest.java | 51 ++++++
.../FirebirdFloatBinaryProtocolValueTest.java | 51 ++++++
.../FirebirdInt16BinaryProtocolValueTest.java | 69 +++++++++
.../FirebirdInt1BinaryProtocolValueTest.java} | 25 ++-
.../FirebirdInt2BinaryProtocolValueTest.java} | 25 ++-
.../FirebirdInt4BinaryProtocolValueTest.java | 61 ++++++++
.../FirebirdInt8BinaryProtocolValueTest.java | 68 ++++++++
.../FirebirdNullBinaryProtocolValueTest.java} | 27 ++--
.../FirebirdStringBinaryProtocolValueTest.java | 61 ++++++++
.../FirebirdTimeBinaryProtocolValueTest.java | 60 +++++++
.../FirebirdTimestampBinaryProtocolValueTest.java | 57 +++++++
...FirebirdTimestampTZBinaryProtocolValueTest.java | 62 ++++++++
.../FirebirdPrepareStatementPacketTest.java | 87 +++++++++++
.../FirebirdPrepareStatementReturnPacketTest.java | 56 +++++++
.../prepare/FirebirdReturnColumnPacketTest.java | 63 ++++++++
.../FirebirdCommitTransactionPacketTest.java} | 26 +++-
.../FirebirdRollbackTransactionPacketTest.java} | 26 +++-
.../generic/FirebirdFetchResponsePacketTest.java | 81 ++++++++++
.../generic/FirebirdGenericResponsePacketTest.java | 93 +++++++++++
.../generic/FirebirdSQLResponsePacketTest.java | 78 ++++++++++
.../handshake/FirebirdAcceptDataPacketTest.java | 66 ++++++++
.../packet/handshake/FirebirdAcceptPacketTest.java | 83 ++++++++++
.../packet/handshake/FirebirdAttachPacketTest.java | 72 +++++++++
.../handshake/FirebirdConnectPacketTest.java | 97 ++++++++++++
.../FirebirdSRPAuthenticationDataTest.java} | 24 ++-
.../frontend/firebird/FirebirdFrontendEngine.java | 2 +-
.../firebird/FirebirdFrontendEngineTest.java | 8 +-
.../FirebirdAuthenticationEngineTest.java} | 43 +++---
.../FirebirdAuthenticatorTypeTest.java | 13 +-
.../impl/FirebirdLegacyAuthenticatorTest.java | 50 ++++++
.../impl/FirebirdSRPAuthenticatorTest.java | 53 +++++++
.../command/FirebirdCommandExecuteEngineTest.java | 172 +++++++++++++++++++++
.../FirebirdUnsupportedCommandExecutorTest.java | 14 +-
.../info/FirebirdDatabaseInfoExecutorTest.java | 56 +++++++
.../query/info/FirebirdSQLInfoExecutorTest.java | 56 +++++++
...rebirdAllocateStatementCommandExecutorTest.java | 70 +++++++++
.../FirebirdFetchStatementCommandExecutorTest.java | 51 ++++++
.../FirebirdFreeStatementCommandExecutorTest.java | 89 +++++++++++
...irebirdExecuteStatementCommandExecutorTest.java | 150 ++++++++++++++++++
...irebirdPrepareStatementCommandExecutorTest.java | 110 +++++++++++++
...rebirdCommitTransactionCommandExecutorTest.java | 61 ++++++++
...birdRollbackTransactionCommandExecutorTest.java | 61 ++++++++
...irebirdStartTransactionCommandExecutorTest.java | 78 ++++++++++
68 files changed, 3847 insertions(+), 127 deletions(-)
diff --git a/db-protocol/firebird/src/main/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersion.java b/db-protocol/firebird/src/main/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersion.java
index db14c34c39f..bdd4d61786c 100644
--- a/db-protocol/firebird/src/main/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersion.java
+++ b/db-protocol/firebird/src/main/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersion.java
@@ -63,11 +63,11 @@ public final class FirebirdConnectionProtocolVersion {
}
/**
- * Unregister connection.
+ * Unset protocol version for connection.
*
* @param connectionId connection ID
*/
- public void unregisterConnection(final int connectionId) {
+ public void unsetProtocolVersion(final int connectionId) {
protocolVersionCache.remove(connectionId);
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
index 41b128641c2..a27297ace19 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
@@ -17,13 +17,63 @@
package org.apache.shardingsphere.db.protocol.firebird.codec;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.CompositeByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.util.AttributeKey;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdConstant;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketFactory;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.mock;
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
class FirebirdPacketCodecEngineTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ChannelHandlerContext context;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private DatabasePacket packet;
+
+ @BeforeEach
+ void setup() {
+ when(context.channel().attr(AttributeKey.<Charset>valueOf(Charset.class.getName())).get()).thenReturn(StandardCharsets.UTF_8);
+ when(context.channel().attr(FirebirdConstant.CONNECTION_PROTOCOL_VERSION).get()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION10);
+ when(context.alloc().compositeBuffer(anyInt())).thenAnswer(inv -> mock(CompositeByteBuf.class, org.mockito.Mockito.RETURNS_SELF));
+ }
+
@Test
void assertIsValidHeader() {
assertTrue(new FirebirdPacketCodecEngine().isValidHeader(50));
@@ -34,5 +84,121 @@ class FirebirdPacketCodecEngineTest {
assertFalse(new FirebirdPacketCodecEngine().isValidHeader(3));
}
- // TODO Add unit tests for the remaining FirebirdPacketCodecEngine logic
+ @Test
+ void assertDecodeSingleAllocateStatement() {
+ ByteBuf in = mock(ByteBuf.class);
+ ByteBuf slice = mock(ByteBuf.class);
+ when(in.readableBytes()).thenReturn(8, 0);
+ when(in.readerIndex()).thenReturn(0);
+ when(in.getInt(0)).thenReturn(FirebirdCommandPacketType.ALLOCATE_STATEMENT.getValue());
+ when(in.readRetainedSlice(8)).thenReturn(slice);
+ when(slice.readableBytes()).thenReturn(8);
+ List<Object> out = new LinkedList<>();
+ new FirebirdPacketCodecEngine().decode(context, in, out);
+ assertThat(out.size(), is(1));
+ assertThat(((ByteBuf) out.get(0)).readableBytes(), is(8));
+ }
+
+ @Test
+ void assertDecodeMultiplePackets() {
+ ByteBuf in = mock(ByteBuf.class);
+ ByteBuf slice1 = mock(ByteBuf.class);
+ ByteBuf slice2 = mock(ByteBuf.class);
+ when(in.readableBytes()).thenReturn(16, 8, 8, 0);
+ when(in.readerIndex()).thenReturn(0);
+ when(in.getInt(0)).thenReturn(FirebirdCommandPacketType.ALLOCATE_STATEMENT.getValue());
+ when(in.readRetainedSlice(8)).thenReturn(slice1, slice2);
+ List<Object> out = new LinkedList<>();
+ new FirebirdPacketCodecEngine().decode(context, in, out);
+ assertThat(out.size(), is(2));
+ }
+
+ @Test
+ void assertDecodeWithPartialPacket() {
+ ByteBuf in = mock(ByteBuf.class);
+ ByteBuf slice = mock(ByteBuf.class);
+ when(in.readableBytes()).thenReturn(8, 8);
+ when(in.readerIndex()).thenReturn(0);
+ when(in.getInt(0)).thenReturn(FirebirdCommandPacketType.TRANSACTION.getValue());
+ when(in.writerIndex()).thenReturn(8);
+ when(in.capacity()).thenReturn(16);
+ when(in.readRetainedSlice(8)).thenReturn(slice);
+ List<Object> out = new LinkedList<>();
+ new FirebirdPacketCodecEngine().decode(context, in, out);
+ assertThat(out.size(), is(1));
+ }
+
+ @Test
+ void assertDecodeWithTruncatedPacketAcrossBuffers() {
+ ByteBuf firstPart = mock(ByteBuf.class);
+ ByteBuf firstSlice = mock(ByteBuf.class);
+ ByteBuf secondPart = mock(ByteBuf.class);
+ ByteBuf secondSlice = mock(ByteBuf.class);
+ CompositeByteBuf firstComposite = mock(CompositeByteBuf.class, org.mockito.Mockito.RETURNS_SELF);
+ CompositeByteBuf secondComposite = mock(CompositeByteBuf.class, org.mockito.Mockito.RETURNS_SELF);
+ when(context.alloc().compositeBuffer(anyInt())).thenReturn(firstComposite, secondComposite);
+ when(firstPart.readableBytes()).thenReturn(8, 8);
+ when(firstPart.readerIndex()).thenReturn(0);
+ when(firstPart.getInt(0)).thenReturn(FirebirdCommandPacketType.PREPARE_STATEMENT.getValue());
+ when(firstPart.writerIndex()).thenReturn(8);
+ when(firstPart.capacity()).thenReturn(8);
+ when(firstPart.readRetainedSlice(8)).thenReturn(firstSlice);
+ when(secondPart.readableBytes()).thenReturn(4);
+ when(secondPart.writerIndex()).thenReturn(4);
+ when(secondPart.capacity()).thenReturn(4);
+ when(secondPart.readRetainedSlice(4)).thenReturn(secondSlice);
+ when(firstComposite.readableBytes()).thenReturn(8);
+ when(secondComposite.readableBytes()).thenReturn(12);
+ List<Object> out = new LinkedList<>();
+ FirebirdPacketCodecEngine codecEngine = new FirebirdPacketCodecEngine();
+ try (MockedStatic<FirebirdCommandPacketFactory> mocked = mockStatic(FirebirdCommandPacketFactory.class)) {
+ mocked.when(() -> FirebirdCommandPacketFactory.isValidLength(any(), any(), anyInt(), any())).thenReturn(false, true);
+ codecEngine.decode(context, firstPart, out);
+ assertTrue(out.isEmpty());
+ codecEngine.decode(context, secondPart, out);
+ assertThat(out.size(), is(1));
+ assertThat(((ByteBuf) out.get(0)).readableBytes(), is(12));
+ }
+ }
+
+ @Test
+ void assertDecodeWithFullBufferAndValidLength() {
+ ByteBuf in = mock(ByteBuf.class);
+ ByteBuf slice = mock(ByteBuf.class);
+ CompositeByteBuf composite = mock(CompositeByteBuf.class, org.mockito.Mockito.RETURNS_SELF);
+ when(context.alloc().compositeBuffer(anyInt())).thenReturn(composite);
+ when(in.readableBytes()).thenReturn(8, 8);
+ when(in.readerIndex()).thenReturn(0);
+ when(in.getInt(0)).thenReturn(FirebirdCommandPacketType.PREPARE_STATEMENT.getValue());
+ when(in.writerIndex()).thenReturn(8);
+ when(in.capacity()).thenReturn(8);
+ when(in.readRetainedSlice(8)).thenReturn(slice);
+ when(composite.readableBytes()).thenReturn(8);
+ when(slice.readableBytes()).thenReturn(8);
+ List<Object> out = new LinkedList<>();
+ try (MockedStatic<FirebirdCommandPacketFactory> mocked = mockStatic(FirebirdCommandPacketFactory.class)) {
+ mocked.when(() -> FirebirdCommandPacketFactory.isValidLength(any(), any(), anyInt(), any())).thenReturn(true);
+ new FirebirdPacketCodecEngine().decode(context, in, out);
+ assertThat(out.size(), is(1));
+ assertThat(((ByteBuf) out.get(0)).readableBytes(), is(8));
+ }
+ }
+
+ @Test
+ void assertEncode() {
+ new FirebirdPacketCodecEngine().encode(context, packet, byteBuf);
+ verify(packet).write(any(FirebirdPacketPayload.class));
+ }
+
+ @Test
+ void assertEncodeOccursException() {
+ doThrow(RuntimeException.class).when(packet).write(any(FirebirdPacketPayload.class));
+ new FirebirdPacketCodecEngine().encode(context, packet, byteBuf);
+ verify(byteBuf).resetWriterIndex();
+ }
+
+ @Test
+ void assertCreatePacketPayload() {
+ assertThat(new FirebirdPacketCodecEngine().createPacketPayload(byteBuf, StandardCharsets.UTF_8).getByteBuf(), is(byteBuf));
+ }
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdAuthenticationMethodTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdAuthenticationMethodTest.java
new file mode 100644
index 00000000000..a502ea6bb04
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdAuthenticationMethodTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.db.protocol.firebird.constant;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class FirebirdAuthenticationMethodTest {
+
+ @Test
+ void assertMethodNamesAndHashAlgorithms() {
+ assertThat(FirebirdAuthenticationMethod.SRP.getMethodName(), is("Srp"));
+ assertThat(FirebirdAuthenticationMethod.SRP.getHashAlgorithm(), is("SHA-1"));
+ assertThat(FirebirdAuthenticationMethod.SRP224.getMethodName(), is("Srp224"));
+ assertThat(FirebirdAuthenticationMethod.SRP224.getHashAlgorithm(), is("SHA-224"));
+ assertThat(FirebirdAuthenticationMethod.SRP256.getMethodName(), is("Srp256"));
+ assertThat(FirebirdAuthenticationMethod.SRP256.getHashAlgorithm(), is("SHA-256"));
+ assertThat(FirebirdAuthenticationMethod.SRP384.getMethodName(), is("Srp384"));
+ assertThat(FirebirdAuthenticationMethod.SRP384.getHashAlgorithm(), is("SHA-384"));
+ assertThat(FirebirdAuthenticationMethod.SRP512.getMethodName(), is("Srp512"));
+ assertThat(FirebirdAuthenticationMethod.SRP512.getHashAlgorithm(), is("SHA-512"));
+ assertThat(FirebirdAuthenticationMethod.LEGACY_AUTH.getMethodName(), is("Legacy_Auth"));
+ assertThat(FirebirdAuthenticationMethod.LEGACY_AUTH.getHashAlgorithm(), is((String) null));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
index 438c76058f7..ebd94ee6371 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
@@ -27,7 +27,7 @@ class FirebirdProtocolDefaultVersionProviderTest {
private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
+ void assertGetDatabaseType() {
assertThat(provider.getDatabaseType(), is("Firebird"));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/buffer/FirebirdParameterBufferTypeTest.java
similarity index 61%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/buffer/FirebirdParameterBufferTypeTest.java
index 438c76058f7..16331288011 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/buffer/FirebirdParameterBufferTypeTest.java
@@ -15,19 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.constant.buffer;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdValueFormat;
+import org.apache.shardingsphere.db.protocol.firebird.constant.buffer.type.FirebirdDatabaseParameterBufferType;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class FirebirdProtocolDefaultVersionProviderTest {
-
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+class FirebirdParameterBufferTypeTest {
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertGetCodeAndFormat() {
+ FirebirdParameterBufferType actual = FirebirdDatabaseParameterBufferType.PAGE_SIZE;
+ assertThat(actual.getCode(), is(FirebirdDatabaseParameterBufferType.PAGE_SIZE.getCode()));
+ assertThat(actual.getFormat(), is(FirebirdValueFormat.INT));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersionTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersionTest.java
new file mode 100644
index 00000000000..4d2450948d4
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/protocol/FirebirdConnectionProtocolVersionTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.db.protocol.firebird.constant.protocol;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class FirebirdConnectionProtocolVersionTest {
+
+ private static final int CONNECTION_ID = 1;
+
+ @AfterEach
+ void tearDown() {
+ FirebirdConnectionProtocolVersion.getInstance().unsetProtocolVersion(CONNECTION_ID);
+ }
+
+ @Test
+ void assertSetAndGetProtocolVersion() {
+ FirebirdConnectionProtocolVersion.getInstance().setProtocolVersion(CONNECTION_ID, FirebirdProtocolVersion.PROTOCOL_VERSION17);
+ assertThat(FirebirdConnectionProtocolVersion.getInstance().getProtocolVersion(CONNECTION_ID),
+ is(FirebirdProtocolVersion.PROTOCOL_VERSION17));
+ }
+
+ @Test
+ void assertUnregisterConnection() {
+ FirebirdConnectionProtocolVersion.getInstance().setProtocolVersion(CONNECTION_ID, FirebirdProtocolVersion.PROTOCOL_VERSION18);
+ FirebirdConnectionProtocolVersion.getInstance().unsetProtocolVersion(CONNECTION_ID);
+ assertNull(FirebirdConnectionProtocolVersion.getInstance().getProtocolVersion(CONNECTION_ID));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketFactoryTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketFactoryTest.java
new file mode 100644
index 00000000000..7ee40e3d770
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketFactoryTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.db.protocol.firebird.packet.command;
+
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.admin.FirebirdUnsupportedCommandPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.FirebirdInfoPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdAllocateStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdFetchStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdFreeStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.FirebirdExecuteStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.prepare.FirebirdPrepareStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdCommitTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdRollbackTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdStartTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdCommandPacketFactoryTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertNewInstanceWithInfoDatabase() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.INFO_DATABASE, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdInfoPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithTransaction() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.TRANSACTION, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdStartTransactionPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithAllocateStatement() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.ALLOCATE_STATEMENT, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdAllocateStatementPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithPrepareStatement() {
+ when(payload.readInt4()).thenReturn(0, 0, 0, 0);
+ when(payload.readString()).thenReturn("");
+ when(payload.readBuffer()).thenReturn(org.mockito.Mockito.mock(io.netty.buffer.ByteBuf.class));
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.PREPARE_STATEMENT, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdPrepareStatementPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithExecuteStatement() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.EXECUTE, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdExecuteStatementPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithFetch() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.FETCH, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdFetchStatementPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithInfoSQL() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.INFO_SQL, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdInfoPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithCommit() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.COMMIT, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdCommitTransactionPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithRollback() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.ROLLBACK, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdRollbackTransactionPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithFreeStatement() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.FREE_STATEMENT, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdFreeStatementPacket.class));
+ }
+
+ @Test
+ void assertNewInstanceWithUnsupportedCommand() {
+ assertThat(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.VOID, payload, FirebirdProtocolVersion.PROTOCOL_VERSION13),
+ instanceOf(FirebirdUnsupportedCommandPacket.class));
+ }
+
+ @Test
+ void assertIsValidLength() {
+ assertThat(FirebirdCommandPacketFactory.isValidLength(FirebirdCommandPacketType.ALLOCATE_STATEMENT, payload,
+ 8, FirebirdProtocolVersion.PROTOCOL_VERSION13), CoreMatchers.is(true));
+ assertThat(FirebirdCommandPacketFactory.isValidLength(FirebirdCommandPacketType.ALLOCATE_STATEMENT, payload,
+ 7, FirebirdProtocolVersion.PROTOCOL_VERSION13), CoreMatchers.is(false));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketTypeTest.java
similarity index 66%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketTypeTest.java
index 438c76058f7..214b39ed48e 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/FirebirdCommandPacketTypeTest.java
@@ -15,19 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-class FirebirdProtocolDefaultVersionProviderTest {
+class FirebirdCommandPacketTypeTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Test
+ void assertValueOf() {
+ assertThat(FirebirdCommandPacketType.valueOf(FirebirdCommandPacketType.CONNECT.getValue()), is(FirebirdCommandPacketType.CONNECT));
+ }
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertValueOfWithIllegalArgument() {
+ assertThrows(NullPointerException.class, () -> FirebirdCommandPacketType.valueOf(-1));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/admin/FirebirdUnsupportedCommandPacketTest.java
similarity index 54%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/admin/FirebirdUnsupportedCommandPacketTest.java
index 41b128641c2..5c974c6cfb8 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/admin/FirebirdUnsupportedCommandPacketTest.java
@@ -15,24 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.codec;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.admin;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-class FirebirdPacketCodecEngineTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdUnsupportedCommandPacketTest {
- @Test
- void assertIsValidHeader() {
- assertTrue(new FirebirdPacketCodecEngine().isValidHeader(50));
- }
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertIsInvalidHeader() {
- assertFalse(new FirebirdPacketCodecEngine().isValidHeader(3));
+ void assertWrite() {
+ assertDoesNotThrow(() -> new FirebirdUnsupportedCommandPacket(FirebirdCommandPacketType.ACCEPT).write(payload));
}
-
- // TODO Add unit tests for the remaining FirebirdPacketCodecEngine logic
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/FirebirdBinaryColumnTypeTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/FirebirdBinaryColumnTypeTest.java
new file mode 100644
index 00000000000..78517dba85a
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/FirebirdBinaryColumnTypeTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query;
+
+import org.firebirdsql.gds.BlrConstants;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Types;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class FirebirdBinaryColumnTypeTest {
+
+ @Test
+ void assertValueOfJDBCAndBLR() {
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.TINYINT), is(FirebirdBinaryColumnType.SHORT));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.SMALLINT), is(FirebirdBinaryColumnType.SHORT));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.INTEGER), is(FirebirdBinaryColumnType.LONG));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.BIGINT), is(FirebirdBinaryColumnType.INT64));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.FLOAT), is(FirebirdBinaryColumnType.FLOAT));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.REAL), is(FirebirdBinaryColumnType.FLOAT));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.DOUBLE), is(FirebirdBinaryColumnType.DOUBLE));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.NUMERIC), is(FirebirdBinaryColumnType.NUMERIC));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.DECIMAL), is(FirebirdBinaryColumnType.DECIMAL));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.CHAR), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.VARCHAR), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.LONGVARCHAR), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.DATE), is(FirebirdBinaryColumnType.DATE));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.TIME), is(FirebirdBinaryColumnType.TIME));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.TIMESTAMP), is(FirebirdBinaryColumnType.TIMESTAMP));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.BINARY), is(FirebirdBinaryColumnType.TEXT));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.VARBINARY), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.LONGVARBINARY), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.NULL), is(FirebirdBinaryColumnType.NULL));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.BLOB), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.BOOLEAN), is(FirebirdBinaryColumnType.BOOLEAN));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.ARRAY), is(FirebirdBinaryColumnType.ARRAY));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.TIME_WITH_TIMEZONE), is(FirebirdBinaryColumnType.TIME_TZ));
+ assertThat(FirebirdBinaryColumnType.valueOfJDBCType(Types.TIMESTAMP_WITH_TIMEZONE), is(FirebirdBinaryColumnType.TIMESTAMP_TZ));
+
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_varying2), is(FirebirdBinaryColumnType.VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_text2), is(FirebirdBinaryColumnType.TEXT));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_text), is(FirebirdBinaryColumnType.LEGACY_TEXT));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_varying), is(FirebirdBinaryColumnType.LEGACY_VARYING));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_double), is(FirebirdBinaryColumnType.DOUBLE));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_float), is(FirebirdBinaryColumnType.FLOAT));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_d_float), is(FirebirdBinaryColumnType.D_FLOAT));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_sql_date), is(FirebirdBinaryColumnType.DATE));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_sql_time), is(FirebirdBinaryColumnType.TIME));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_timestamp), is(FirebirdBinaryColumnType.TIMESTAMP));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_quad), is(FirebirdBinaryColumnType.BLOB));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_long), is(FirebirdBinaryColumnType.LONG));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_short), is(FirebirdBinaryColumnType.SHORT));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_int64), is(FirebirdBinaryColumnType.INT64));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_bool), is(FirebirdBinaryColumnType.BOOLEAN));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_dec64), is(FirebirdBinaryColumnType.DEC16));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_dec128), is(FirebirdBinaryColumnType.DEC34));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_int128), is(FirebirdBinaryColumnType.INT128));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_timestamp_tz), is(FirebirdBinaryColumnType.TIMESTAMP_TZ));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_sql_time_tz), is(FirebirdBinaryColumnType.TIME_TZ));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_ex_timestamp_tz), is(FirebirdBinaryColumnType.TIMESTAMP_TZ_EX));
+ assertThat(FirebirdBinaryColumnType.valueOfBLRType(BlrConstants.blr_ex_time_tz), is(FirebirdBinaryColumnType.TIME_TZ_EX));
+ }
+
+ @Test
+ void assertValueOfJDBCIllegalArgument() {
+ assertThrows(IllegalArgumentException.class, () -> FirebirdBinaryColumnType.valueOfJDBCType(9999));
+ }
+
+ @Test
+ void assertValueOfBLRTypeIllegalArgument() {
+ assertThrows(IllegalArgumentException.class, () -> FirebirdBinaryColumnType.valueOfBLRType(-100));
+ }
+
+ @Test
+ void assertValueOf() {
+ assertThat(FirebirdBinaryColumnType.valueOf(FirebirdBinaryColumnType.DECIMAL.getValue()), is(FirebirdBinaryColumnType.DECIMAL));
+ }
+
+ @Test
+ void assertValueOfWithIllegalArgument() {
+ assertThrows(IllegalArgumentException.class, () -> FirebirdBinaryColumnType.valueOf(-1));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTest.java
new file mode 100644
index 00000000000..aeb67c33ce1
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.info;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.common.FirebirdCommonInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdInfoPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertGetLength() {
+ when(payload.getBufferLength(12)).thenReturn(8);
+ assertThat(FirebirdInfoPacket.getLength(payload), is(24));
+ }
+
+ @Test
+ void assertNewInstance() {
+ when(payload.readInt4()).thenReturn(1, 2, 100);
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ when(byteBuf.isReadable()).thenReturn(true, true, false);
+ when(byteBuf.readByte()).thenReturn((byte) FirebirdSQLInfoPacketType.RECORDS.getCode(), (byte) FirebirdCommonInfoPacketType.END.getCode());
+ FirebirdInfoPacket actual = new FirebirdInfoPacket(payload, FirebirdSQLInfoPacketType::valueOf);
+ assertThat(actual.getHandle(), is(1));
+ assertThat(actual.getIncarnation(), is(2));
+ assertThat(actual.getMaxLength(), is(100));
+ List<FirebirdInfoPacketType> infoItems = actual.getInfoItems();
+ assertThat(infoItems.get(0), is(FirebirdSQLInfoPacketType.RECORDS));
+ assertThat(infoItems.get(1), is(FirebirdCommonInfoPacketType.END));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTypeTest.java
similarity index 52%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTypeTest.java
index 41b128641c2..aa926080a0d 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/FirebirdInfoPacketTypeTest.java
@@ -15,24 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.codec;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.common.FirebirdCommonInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
-class FirebirdPacketCodecEngineTest {
+class FirebirdInfoPacketTypeTest {
@Test
- void assertIsValidHeader() {
- assertTrue(new FirebirdPacketCodecEngine().isValidHeader(50));
+ void assertSQLInfoPacketType() {
+ FirebirdInfoPacketType type = FirebirdSQLInfoPacketType.RECORDS;
+ assertThat(type.getCode(), is(FirebirdSQLInfoPacketType.RECORDS.getCode()));
+ assertFalse(type.isCommon());
}
@Test
- void assertIsInvalidHeader() {
- assertFalse(new FirebirdPacketCodecEngine().isValidHeader(3));
+ void assertCommonInfoPacketType() {
+ FirebirdInfoPacketType type = FirebirdCommonInfoPacketType.END;
+ assertThat(type.getCode(), is(FirebirdCommonInfoPacketType.END.getCode()));
+ assertTrue(type.isCommon());
}
-
- // TODO Add unit tests for the remaining FirebirdPacketCodecEngine logic
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/common/FirebirdCommonInfoPacketTypeTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/common/FirebirdCommonInfoPacketTypeTest.java
new file mode 100644
index 00000000000..02f2eecee6e
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/common/FirebirdCommonInfoPacketTypeTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.info.type.common;
+
+import org.apache.shardingsphere.db.protocol.firebird.exception.FirebirdProtocolException;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdCommonInfoPacketTypeTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertValueOf() {
+ assertThat(FirebirdCommonInfoPacketType.valueOf(FirebirdCommonInfoPacketType.END.getCode()),
+ is(FirebirdCommonInfoPacketType.END));
+ }
+
+ @Test
+ void assertParseCommonInfo() {
+ FirebirdCommonInfoPacketType.parseCommonInfo(payload, FirebirdCommonInfoPacketType.END);
+ verify(payload).writeInt1(FirebirdCommonInfoPacketType.END.getCode());
+ }
+
+ @Test
+ void assertParseCommonInfoWithUnknownType() {
+ assertThrows(FirebirdProtocolException.class, () -> FirebirdCommonInfoPacketType.parseCommonInfo(payload, FirebirdCommonInfoPacketType.ERROR));
+ }
+
+ @Test
+ void assertIsCommon() {
+ assertThat(FirebirdCommonInfoPacketType.DATA_NOT_READY.isCommon(), is(true));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoPacketTypeTest.java
similarity index 66%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoPacketTypeTest.java
index 438c76058f7..80b87a72cd2 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoPacketTypeTest.java
@@ -15,19 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.database;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class FirebirdProtocolDefaultVersionProviderTest {
+class FirebirdDatabaseInfoPacketTypeTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Test
+ void assertValueOf() {
+ assertThat(FirebirdDatabaseInfoPacketType.valueOf(FirebirdDatabaseInfoPacketType.DB_SQL_DIALECT.getCode()),
+ is(FirebirdDatabaseInfoPacketType.DB_SQL_DIALECT));
+ }
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertIsCommon() {
+ assertThat(FirebirdDatabaseInfoPacketType.DB_SIZE_IN_PAGES.isCommon(), is(false));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoReturnPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoReturnPacketTest.java
new file mode 100644
index 00000000000..bafc950ba22
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/database/FirebirdDatabaseInfoReturnPacketTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.info.type.database;
+
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdArchType;
+import org.apache.shardingsphere.db.protocol.firebird.exception.FirebirdProtocolException;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.mockito.Mockito.inOrder;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdDatabaseInfoReturnPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertWriteDialect() {
+ FirebirdDatabaseInfoReturnPacket packet = new FirebirdDatabaseInfoReturnPacket(Collections.singletonList(FirebirdDatabaseInfoPacketType.DB_SQL_DIALECT));
+ packet.write(payload);
+ InOrder order = inOrder(payload);
+ order.verify(payload).writeInt1(FirebirdDatabaseInfoPacketType.DB_SQL_DIALECT.getCode());
+ order.verify(payload).writeInt2LE(1);
+ order.verify(payload).writeInt1(3);
+ }
+
+ @Test
+ void assertWriteOdsVersion() {
+ FirebirdDatabaseInfoReturnPacket packet = new FirebirdDatabaseInfoReturnPacket(Collections.singletonList(FirebirdDatabaseInfoPacketType.ODS_VERSION));
+ packet.write(payload);
+ InOrder order = inOrder(payload);
+ order.verify(payload).writeInt1(FirebirdDatabaseInfoPacketType.ODS_VERSION.getCode());
+ order.verify(payload).writeInt2LE(4);
+ order.verify(payload).writeInt4LE(5);
+ }
+
+ @Test
+ void assertWriteOdsMinorVersion() {
+ FirebirdDatabaseInfoReturnPacket packet = new FirebirdDatabaseInfoReturnPacket(Collections.singletonList(FirebirdDatabaseInfoPacketType.ODS_MINOR_VERSION));
+ packet.write(payload);
+ InOrder order = inOrder(payload);
+ order.verify(payload).writeInt1(FirebirdDatabaseInfoPacketType.ODS_MINOR_VERSION.getCode());
+ order.verify(payload).writeInt2LE(4);
+ order.verify(payload).writeInt4LE(0);
+ }
+
+ @Test
+ void assertWriteFirebirdVersion() {
+ FirebirdDatabaseInfoReturnPacket packet = new FirebirdDatabaseInfoReturnPacket(Collections.singletonList(FirebirdDatabaseInfoPacketType.FIREBIRD_VERSION));
+ packet.write(payload);
+ String serverName = String.format("Firebird %d.%d (ShardingSphere-Proxy)", 5, 0);
+ String fbVersion = String.format("%s-%s%d.%d.%d.%d %s", FirebirdArchType.ARCHITECTURE.getIdentifier(), "V", 5, 0, 0, 0, serverName);
+ InOrder order = inOrder(payload);
+ order.verify(payload).writeInt1(FirebirdDatabaseInfoPacketType.FIREBIRD_VERSION.getCode());
+ order.verify(payload).writeInt2LE(fbVersion.length() + 2);
+ order.verify(payload).writeInt1(1);
+ order.verify(payload).writeInt1(fbVersion.length());
+ order.verify(payload).writeBytes(fbVersion.getBytes(StandardCharsets.UTF_8));
+ }
+
+ @Test
+ void assertParseDatabaseInfoWithUnknownType() {
+ FirebirdDatabaseInfoReturnPacket packet = new FirebirdDatabaseInfoReturnPacket(Collections.singletonList(FirebirdDatabaseInfoPacketType.DB_ID));
+ assertThrows(FirebirdProtocolException.class, () -> packet.write(payload));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoPacketTypeTest.java
similarity index 69%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoPacketTypeTest.java
index 438c76058f7..90ea5464361 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoPacketTypeTest.java
@@ -15,19 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class FirebirdProtocolDefaultVersionProviderTest {
+class FirebirdSQLInfoPacketTypeTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Test
+ void assertValueOf() {
+ assertThat(FirebirdSQLInfoPacketType.valueOf(FirebirdSQLInfoPacketType.STMT_TYPE.getCode()),
+ is(FirebirdSQLInfoPacketType.STMT_TYPE));
+ }
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertIsCommon() {
+ assertThat(FirebirdSQLInfoPacketType.TYPE.isCommon(), is(false));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnPacketTest.java
new file mode 100644
index 00000000000..270923ed8f5
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnPacketTest.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.db.protocol.firebird.packet.command.query.info.type.sql;
+
+import org.apache.shardingsphere.db.protocol.firebird.exception.FirebirdProtocolException;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.common.FirebirdCommonInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdSQLInfoReturnPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertWriteRecords() {
+ FirebirdSQLInfoReturnPacket packet = new FirebirdSQLInfoReturnPacket(Arrays.asList(FirebirdSQLInfoPacketType.RECORDS, FirebirdCommonInfoPacketType.END));
+ packet.write(payload);
+ org.mockito.InOrder io = org.mockito.Mockito.inOrder(payload);
+ io.verify(payload).writeInt1(FirebirdSQLInfoPacketType.RECORDS.getCode());
+ io.verify(payload).writeInt2LE(0);
+ io.verify(payload).writeInt1(FirebirdSQLInfoReturnValue.SELECT.getCode());
+ io.verify(payload).writeInt2LE(4);
+ io.verify(payload).writeInt4LE(0);
+ io.verify(payload).writeInt1(FirebirdSQLInfoReturnValue.INSERT.getCode());
+ io.verify(payload).writeInt2LE(4);
+ io.verify(payload).writeInt4LE(0);
+ io.verify(payload).writeInt1(FirebirdSQLInfoReturnValue.UPDATE.getCode());
+ io.verify(payload).writeInt2LE(4);
+ io.verify(payload).writeInt4LE(0);
+ io.verify(payload).writeInt1(FirebirdSQLInfoReturnValue.DELETE.getCode());
+ io.verify(payload).writeInt2LE(4);
+ io.verify(payload).writeInt4LE(0);
+ io.verify(payload).writeInt1(FirebirdCommonInfoPacketType.END.getCode());
+ }
+
+ @Test
+ void assertParseSQLInfoWithUnknownType() {
+ FirebirdSQLInfoReturnPacket packet = new FirebirdSQLInfoReturnPacket(Collections.singletonList(FirebirdSQLInfoPacketType.STMT_TYPE));
+ assertThrows(FirebirdProtocolException.class, () -> packet.write(payload));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnValueTest.java
similarity index 73%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnValueTest.java
index 438c76058f7..2126b7fd47f 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/info/type/sql/FirebirdSQLInfoReturnValueTest.java
@@ -15,19 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class FirebirdProtocolDefaultVersionProviderTest {
-
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+class FirebirdSQLInfoReturnValueTest {
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertValueOf() {
+ assertThat(FirebirdSQLInfoReturnValue.valueOf(FirebirdSQLInfoReturnValue.SELECT.getCode()),
+ is(FirebirdSQLInfoReturnValue.SELECT));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdAllocateStatementPacketTest.java
similarity index 51%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdAllocateStatementPacketTest.java
index 438c76058f7..f60eed18298 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdAllocateStatementPacketTest.java
@@ -15,19 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-class FirebirdProtocolDefaultVersionProviderTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdAllocateStatementPacketTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertAllocateStatementPacket() {
+ when(payload.readInt4()).thenReturn(1);
+ FirebirdAllocateStatementPacket packet = new FirebirdAllocateStatementPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getDatabaseId(), is(1));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(FirebirdAllocateStatementPacket.getLength(), is(8));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFetchStatementPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFetchStatementPacketTest.java
new file mode 100644
index 00000000000..3a3daf76681
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFetchStatementPacketTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.firebirdsql.gds.BlrConstants;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFetchStatementPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertFetchStatementPacket() {
+ when(payload.readInt4()).thenReturn(3, 7, 10);
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ when(byteBuf.isReadable()).thenReturn(true);
+ when(byteBuf.readUnsignedByte()).thenReturn((short) 9, (short) 0, (short) BlrConstants.blr_long, (short) BlrConstants.blr_short, (short) BlrConstants.blr_end);
+ when(byteBuf.skipBytes(anyInt())).thenReturn(byteBuf);
+ FirebirdFetchStatementPacket packet = new FirebirdFetchStatementPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getStatementId(), is(3));
+ assertThat(packet.getMessage(), is(7));
+ assertThat(packet.getFetchSize(), is(10));
+ assertThat(packet.getParameterTypes().size(), is(2));
+ assertThat(packet.getParameterTypes().get(0), is(FirebirdBinaryColumnType.LONG));
+ assertThat(packet.getParameterTypes().get(1), is(FirebirdBinaryColumnType.SHORT));
+ }
+
+ @Test
+ void assertGetLength() {
+ when(payload.getBufferLength(8)).thenReturn(20);
+ assertThat(FirebirdFetchStatementPacket.getLength(payload), is(36));
+ verify(payload).getBufferLength(8);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFreeStatementPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFreeStatementPacketTest.java
new file mode 100644
index 00000000000..2aa5079ab5e
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/FirebirdFreeStatementPacketTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement;
+
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFreeStatementPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertFreeStatementPacket() {
+ when(payload.readInt4()).thenReturn(5, FirebirdFreeStatementPacket.DROP);
+ FirebirdFreeStatementPacket packet = new FirebirdFreeStatementPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getStatementId(), is(5));
+ assertThat(packet.getOption(), is(FirebirdFreeStatementPacket.DROP));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(FirebirdFreeStatementPacket.getLength(), is(12));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
new file mode 100644
index 00000000000..d493e942896
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.firebirdsql.gds.BlrConstants;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdExecuteStatementPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertExecuteStatementPacket() {
+ when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(), 1, 2, 0, 1, 123);
+ when(payload.readInt1()).thenReturn(0);
+ doNothing().when(payload).skipPadding(anyInt());
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ when(byteBuf.isReadable()).thenReturn(true);
+ when(byteBuf.readUnsignedByte()).thenReturn((short) 5, (short) 0, (short) BlrConstants.blr_long, (short) BlrConstants.blr_end);
+ when(byteBuf.skipBytes(anyInt())).thenReturn(byteBuf);
+ FirebirdExecuteStatementPacket packet = new FirebirdExecuteStatementPacket(payload, FirebirdProtocolVersion.PROTOCOL_VERSION13);
+ assertThat(packet.getType(), is(FirebirdCommandPacketType.EXECUTE));
+ assertThat(packet.getStatementId(), is(1));
+ assertThat(packet.getTransactionId(), is(2));
+ assertThat(packet.getParameterTypes(), is(Collections.singletonList(FirebirdBinaryColumnType.LONG)));
+ assertThat(packet.getParameterValues(), is(Collections.singletonList(123)));
+ }
+
+ @Test
+ void assertExecuteStatementPacketForStoredProcedure() {
+ when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE2.getValue(), 1, 2, 0, 1, 123, 9);
+ when(payload.readInt1()).thenReturn(0);
+ doNothing().when(payload).skipPadding(anyInt());
+ ByteBuf returnBlr = mock(ByteBuf.class);
+ when(payload.readBuffer()).thenReturn(byteBuf, returnBlr);
+ when(byteBuf.isReadable()).thenReturn(true);
+ when(byteBuf.readUnsignedByte()).thenReturn((short) 5, (short) 0, (short) BlrConstants.blr_long, (short) BlrConstants.blr_end);
+ when(byteBuf.skipBytes(anyInt())).thenReturn(byteBuf);
+ when(returnBlr.isReadable()).thenReturn(true);
+ when(returnBlr.readUnsignedByte()).thenReturn((short) 5, (short) 0, (short) BlrConstants.blr_long, (short) BlrConstants.blr_end);
+ when(returnBlr.skipBytes(anyInt())).thenReturn(returnBlr);
+ when(payload.readInt4Unsigned()).thenReturn(30L, 1L, 1024L);
+ FirebirdExecuteStatementPacket packet = new FirebirdExecuteStatementPacket(payload, FirebirdProtocolVersion.PROTOCOL_VERSION19);
+ assertThat(packet.isStoredProcedure(), is(true));
+ assertThat(packet.getReturnColumns(), is(Collections.singletonList(FirebirdBinaryColumnType.LONG)));
+ assertThat(packet.getOutputMessageNumber(), is(9));
+ assertThat(packet.getParameterValues(), is(Collections.singletonList(123)));
+ assertThat(packet.getStatementTimeout(), is(30L));
+ assertThat(packet.getCursorFlags(), is(1L));
+ assertThat(packet.getMaxBlobSize(), is(1024L));
+ }
+
+ @Test
+ void assertGetLength() {
+ when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(), 1, 2, 0, 1, 123);
+ when(payload.readInt1()).thenReturn(0);
+ doNothing().when(payload).skipPadding(anyInt());
+ ByteBuf blr = mock(ByteBuf.class);
+ when(payload.readBuffer()).thenReturn(blr);
+ when(blr.isReadable()).thenReturn(true);
+ when(blr.readUnsignedByte()).thenReturn((short) 5, (short) 0, (short) BlrConstants.blr_long, (short) BlrConstants.blr_end);
+ when(blr.skipBytes(anyInt())).thenReturn(blr);
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.readerIndex()).thenReturn(42);
+ assertThat(FirebirdExecuteStatementPacket.getLength(payload, FirebirdProtocolVersion.PROTOCOL_VERSION13), is(42));
+ verify(byteBuf).resetReaderIndex();
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
new file mode 100644
index 00000000000..535d5c89096
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class FirebirdBinaryProtocolValueFactoryTest {
+
+ @Test
+ void assertGetStringBinaryProtocolValueByVarying() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.VARYING);
+ assertThat(actual, instanceOf(FirebirdStringBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetByteBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.BLOB);
+ assertThat(actual, instanceOf(FirebirdByteBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetInt16BinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.INT128);
+ assertThat(actual, instanceOf(FirebirdInt16BinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetInt8BinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.INT64);
+ assertThat(actual, instanceOf(FirebirdInt8BinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetInt4BinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.LONG);
+ assertThat(actual, instanceOf(FirebirdInt4BinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetInt2BinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.SHORT);
+ assertThat(actual, instanceOf(FirebirdInt2BinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetInt1BinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.BOOLEAN);
+ assertThat(actual, instanceOf(FirebirdInt1BinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetDoubleBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.DOUBLE);
+ assertThat(actual, instanceOf(FirebirdDoubleBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetFloatBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.FLOAT);
+ assertThat(actual, instanceOf(FirebirdFloatBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetDateBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.DATE);
+ assertThat(actual, instanceOf(FirebirdDateBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetTimeBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.TIME);
+ assertThat(actual, instanceOf(FirebirdTimeBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetTimestampBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.TIMESTAMP);
+ assertThat(actual, instanceOf(FirebirdTimestampBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetTimestampTZBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.TIMESTAMP_TZ);
+ assertThat(actual, instanceOf(FirebirdTimestampTZBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetNullBinaryProtocolValue() {
+ FirebirdBinaryProtocolValue actual = FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.NULL);
+ assertThat(actual, instanceOf(FirebirdNullBinaryProtocolValue.class));
+ }
+
+ @Test
+ void assertGetBinaryProtocolValueExThrown() {
+ assertThrows(IllegalArgumentException.class, () -> FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.TIME_TZ_EX));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdByteBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdByteBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..af33383c9cc
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdByteBinaryProtocolValueTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdByteBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertRead() {
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ assertThat(new FirebirdByteBinaryProtocolValue().read(payload), is(byteBuf));
+ }
+
+ @Test
+ void assertWriteWithString() {
+ new FirebirdByteBinaryProtocolValue().write(payload, "foo");
+ verify(payload).writeString("foo");
+ }
+
+ @Test
+ void assertWriteWithBytes() {
+ byte[] bytes = {1, 2};
+ new FirebirdByteBinaryProtocolValue().write(payload, bytes);
+ verify(payload).writeBuffer(bytes);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDateBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDateBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..1026c30554e
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDateBinaryProtocolValueTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.util.FirebirdDateTimeUtils;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdDateBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ LocalDateTime date = LocalDateTime.of(2024, 1, 1, 0, 0);
+ int encoded = FirebirdDateTimeUtils.getEncodedDate(date);
+ when(payload.readInt4()).thenReturn(encoded);
+ assertThat(new FirebirdDateBinaryProtocolValue().read(payload), is(FirebirdDateTimeUtils.getDate(encoded)));
+ }
+
+ @Test
+ void assertWrite() {
+ LocalDateTime date = LocalDateTime.of(2024, 1, 1, 0, 0);
+ new FirebirdDateBinaryProtocolValue().write(payload, Timestamp.valueOf(date));
+ verify(payload).writeInt4(FirebirdDateTimeUtils.getEncodedDate(date));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDoubleBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDoubleBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..bd834fb8b62
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdDoubleBinaryProtocolValueTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdDoubleBinaryProtocolValueTest {
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertRead() {
+ when(byteBuf.readDouble()).thenReturn(1.0D);
+ assertThat(new FirebirdDoubleBinaryProtocolValue().read(new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8)), is(1.0D));
+ }
+
+ @Test
+ void assertWrite() {
+ new FirebirdDoubleBinaryProtocolValue().write(new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8), 1.0D);
+ verify(byteBuf).writeDouble(1.0D);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdFloatBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdFloatBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..4d1abdf0724
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdFloatBinaryProtocolValueTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFloatBinaryProtocolValueTest {
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertRead() {
+ when(byteBuf.readFloat()).thenReturn(1.0F);
+ assertThat(new FirebirdFloatBinaryProtocolValue().read(new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8)), is(1.0F));
+ }
+
+ @Test
+ void assertWrite() {
+ new FirebirdFloatBinaryProtocolValue().write(new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8), 1.0F);
+ verify(byteBuf).writeFloat(1.0F);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java
new file mode 100644
index 00000000000..5e077d1979c
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt16BinaryProtocolValueTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.math.BigDecimal;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdInt16BinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private ByteBuf result;
+
+ @Test
+ void assertRead() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.readSlice(16)).thenReturn(result);
+ assertThat(new FirebirdInt16BinaryProtocolValue().read(payload), is(result));
+ }
+
+ @Test
+ void assertWriteWithInteger() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ new FirebirdInt16BinaryProtocolValue().write(payload, 1);
+ verify(byteBuf).writeZero(12);
+ verify(payload).writeInt4(1);
+ }
+
+ @Test
+ void assertWriteWithBigDecimal() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ new FirebirdInt16BinaryProtocolValue().write(payload, BigDecimal.ONE);
+ verify(byteBuf).writeZero(15);
+ verify(byteBuf).writeBytes(eq(new byte[]{1}));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
similarity index 53%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
index 438c76058f7..ee4e45693e1 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
@@ -15,19 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-class FirebirdProtocolDefaultVersionProviderTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdInt1BinaryProtocolValueTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertRead() {
+ when(payload.readInt1Unsigned()).thenReturn(1);
+ assertThat(new FirebirdInt1BinaryProtocolValue().read(payload), is(1));
+ }
+
+ @Test
+ void assertWrite() {
+ new FirebirdInt1BinaryProtocolValue().write(payload, 1);
+ verify(payload).writeInt2(1);
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt2BinaryProtocolValueTest.java
similarity index 53%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt2BinaryProtocolValueTest.java
index 438c76058f7..45447dbe9c1 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt2BinaryProtocolValueTest.java
@@ -15,19 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-class FirebirdProtocolDefaultVersionProviderTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdInt2BinaryProtocolValueTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertRead() {
+ when(payload.readInt4()).thenReturn(1);
+ assertThat(new FirebirdInt2BinaryProtocolValue().read(payload), is(1));
+ }
+
+ @Test
+ void assertWrite() {
+ new FirebirdInt2BinaryProtocolValue().write(payload, 1);
+ verify(payload).writeInt4(1);
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt4BinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt4BinaryProtocolValueTest.java
new file mode 100644
index 00000000000..21c89e1004b
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt4BinaryProtocolValueTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.math.BigDecimal;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdInt4BinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ when(payload.readInt4()).thenReturn(1);
+ new FirebirdInt4BinaryProtocolValue().read(payload);
+ verify(payload).readInt4();
+ }
+
+ @Test
+ void assertWriteWithBigDecimal() {
+ new FirebirdInt4BinaryProtocolValue().write(payload, BigDecimal.ONE);
+ verify(payload).writeInt4(1);
+ }
+
+ @Test
+ void assertWriteWithInteger() {
+ new FirebirdInt4BinaryProtocolValue().write(payload, 1);
+ verify(payload).writeInt4(1);
+ }
+
+ @Test
+ void assertWriteWithLong() {
+ new FirebirdInt4BinaryProtocolValue().write(payload, 1L);
+ verify(payload).writeInt4(1);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt8BinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt8BinaryProtocolValueTest.java
new file mode 100644
index 00000000000..b460af83b23
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt8BinaryProtocolValueTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdInt8BinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ when(payload.readInt8()).thenReturn(1L);
+ new FirebirdInt8BinaryProtocolValue().read(payload);
+ verify(payload).readInt8();
+ }
+
+ @Test
+ void assertWriteWithBigDecimal() {
+ new FirebirdInt8BinaryProtocolValue().write(payload, BigDecimal.ONE);
+ verify(payload).writeInt8(1L);
+ }
+
+ @Test
+ void assertWriteWithInteger() {
+ new FirebirdInt8BinaryProtocolValue().write(payload, 1);
+ verify(payload).writeInt8(1L);
+ }
+
+ @Test
+ void assertWriteWithBigInteger() {
+ new FirebirdInt8BinaryProtocolValue().write(payload, BigInteger.ONE);
+ verify(payload).writeInt8(1L);
+ }
+
+ @Test
+ void assertWriteWithLong() {
+ new FirebirdInt8BinaryProtocolValue().write(payload, 1L);
+ verify(payload).writeInt8(1L);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdNullBinaryProtocolValueTest.java
similarity index 52%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdNullBinaryProtocolValueTest.java
index 41b128641c2..c239ed64b1a 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/codec/FirebirdPacketCodecEngineTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdNullBinaryProtocolValueTest.java
@@ -15,24 +15,31 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.codec;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.verify;
-class FirebirdPacketCodecEngineTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdNullBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertIsValidHeader() {
- assertTrue(new FirebirdPacketCodecEngine().isValidHeader(50));
+ void assertRead() {
+ assertNull(new FirebirdNullBinaryProtocolValue().read(payload));
}
@Test
- void assertIsInvalidHeader() {
- assertFalse(new FirebirdPacketCodecEngine().isValidHeader(3));
+ void assertWrite() {
+ new FirebirdNullBinaryProtocolValue().write(payload, null);
+ verify(payload).writeBuffer(new byte[0]);
}
-
- // TODO Add unit tests for the remaining FirebirdPacketCodecEngine logic
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdStringBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdStringBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..7683016b0dd
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdStringBinaryProtocolValueTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdStringBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ when(payload.readString()).thenReturn("foo");
+ assertThat(new FirebirdStringBinaryProtocolValue().read(payload), is("foo"));
+ }
+
+ @Test
+ void assertWriteWithBytes() {
+ byte[] bytes = {1};
+ new FirebirdStringBinaryProtocolValue().write(payload, bytes);
+ verify(payload).writeBuffer(bytes);
+ }
+
+ @Test
+ void assertWriteWithString() {
+ new FirebirdStringBinaryProtocolValue().write(payload, "bar");
+ verify(payload).writeString("bar");
+ }
+
+ @Test
+ void assertWriteWithNull() {
+ new FirebirdStringBinaryProtocolValue().write(payload, null);
+ verify(payload).writeString("");
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimeBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimeBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..20c9722be29
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimeBinaryProtocolValueTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.util.FirebirdDateTimeUtils;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.Time;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdTimeBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ LocalDateTime dateTime = LocalDateTime.of(1970, 1, 1, 12, 0, 0);
+ int encoded = new FirebirdDateTimeUtils(dateTime).getEncodedTime();
+ when(payload.readInt4()).thenReturn(encoded);
+ assertThat(new FirebirdTimeBinaryProtocolValue().read(payload), is(FirebirdDateTimeUtils.getTime(encoded)));
+ }
+
+ @Test
+ void assertWrite() {
+ Time time = Time.valueOf(LocalTime.of(12, 0, 0));
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(time.getTime()), ZoneId.systemDefault());
+ int encoded = new FirebirdDateTimeUtils(localDateTime).getEncodedTime();
+ new FirebirdTimeBinaryProtocolValue().write(payload, time);
+ verify(payload).writeInt4(encoded);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..b1d1c9a20c1
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampBinaryProtocolValueTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.util.FirebirdDateTimeUtils;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdTimestampBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ LocalDateTime dateTime = LocalDateTime.of(2024, 1, 1, 12, 0);
+ int encodedDate = FirebirdDateTimeUtils.getEncodedDate(dateTime);
+ int encodedTime = new FirebirdDateTimeUtils(dateTime).getEncodedTime();
+ when(payload.readInt4()).thenReturn(encodedDate, encodedTime);
+ assertThat(new FirebirdTimestampBinaryProtocolValue().read(payload), is(FirebirdDateTimeUtils.getDateTime(encodedDate, encodedTime)));
+ }
+
+ @Test
+ void assertWrite() {
+ LocalDateTime dateTime = LocalDateTime.of(2024, 1, 1, 12, 0);
+ new FirebirdTimestampBinaryProtocolValue().write(payload, Timestamp.valueOf(dateTime));
+ verify(payload).writeInt4(FirebirdDateTimeUtils.getEncodedDate(dateTime));
+ verify(payload).writeInt4(new FirebirdDateTimeUtils(dateTime).getEncodedTime());
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampTZBinaryProtocolValueTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampTZBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..c7c31dbccf6
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdTimestampTZBinaryProtocolValueTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.util.FirebirdDateTimeUtils;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdTimestampTZBinaryProtocolValueTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertRead() {
+ LocalDateTime dateTime = LocalDateTime.of(2024, 1, 1, 12, 0);
+ int encodedDate = FirebirdDateTimeUtils.getEncodedDate(dateTime);
+ int encodedTime = new FirebirdDateTimeUtils(dateTime).getEncodedTime();
+ when(payload.readInt4()).thenReturn(encodedDate, encodedTime, 60);
+ assertThat(new FirebirdTimestampTZBinaryProtocolValue().read(payload), is(FirebirdDateTimeUtils.getDateTimeWithOffset(encodedDate, encodedTime, 60)));
+ }
+
+ @Test
+ void assertWrite() {
+ OffsetDateTime value = OffsetDateTime.of(LocalDateTime.of(2024, 1, 1, 12, 0), ZoneOffset.ofHours(2));
+ LocalDateTime utc = value.atZoneSameInstant(ZoneOffset.UTC).toLocalDateTime();
+ int encodedDate = FirebirdDateTimeUtils.getEncodedDate(utc);
+ int encodedTime = new FirebirdDateTimeUtils(utc).getEncodedTime();
+ new FirebirdTimestampTZBinaryProtocolValue().write(payload, value);
+ verify(payload).writeInt4(encodedDate);
+ verify(payload).writeInt4(encodedTime);
+ verify(payload).writeInt4(120);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementPacketTest.java
new file mode 100644
index 00000000000..bb03fcf5b80
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementPacketTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.prepare;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdPrepareStatementPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertPrepareStatementPacket() {
+ doNothing().when(payload).skipReserved(anyInt());
+ when(payload.readInt4()).thenReturn(1, 2, 3, 10);
+ when(payload.readString()).thenReturn("select 1");
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ when(byteBuf.isReadable()).thenReturn(true, true, false);
+ when(byteBuf.readByte()).thenReturn((byte) FirebirdSQLInfoPacketType.STMT_TYPE.getCode(), (byte) FirebirdSQLInfoPacketType.DESCRIBE_VARS.getCode());
+ FirebirdPrepareStatementPacket packet = new FirebirdPrepareStatementPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getTransactionId(), is(1));
+ assertThat(packet.getStatementId(), is(2));
+ assertThat(packet.getSqlDialect(), is(3));
+ assertThat(packet.getSQL(), is("select 1"));
+ assertTrue(packet.isValidStatementHandle());
+ assertTrue(packet.nextItem());
+ assertThat(packet.getCurrentItem(), is(FirebirdSQLInfoPacketType.STMT_TYPE));
+ assertTrue(packet.nextItem());
+ assertThat(packet.getCurrentItem(), is(FirebirdSQLInfoPacketType.DESCRIBE_VARS));
+ assertFalse(packet.nextItem());
+ }
+
+ @Test
+ void assertIsValidStatementHandleWhenInvalid() {
+ doNothing().when(payload).skipReserved(anyInt());
+ when(payload.readInt4()).thenReturn(1, 0xFFFF, 3, 10);
+ when(payload.readString()).thenReturn("select 1");
+ when(payload.readBuffer()).thenReturn(byteBuf);
+ when(byteBuf.isReadable()).thenReturn(false);
+ FirebirdPrepareStatementPacket packet = new FirebirdPrepareStatementPacket(payload);
+ assertFalse(packet.isValidStatementHandle());
+ }
+
+ @Test
+ void assertGetLength() {
+ when(payload.getBufferLength(16)).thenReturn(12);
+ when(payload.getBufferLength(28)).thenReturn(8);
+ assertThat(FirebirdPrepareStatementPacket.getLength(payload), is(40));
+ verify(payload).getBufferLength(16);
+ verify(payload).getBufferLength(28);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementReturnPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementReturnPacketTest.java
new file mode 100644
index 00000000000..149f3f64c4c
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdPrepareStatementReturnPacketTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.prepare;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.common.FirebirdCommonInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoReturnValue;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.Types;
+import java.util.Collections;
+
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdPrepareStatementReturnPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertWrite() {
+ FirebirdPrepareStatementReturnPacket packet = new FirebirdPrepareStatementReturnPacket();
+ packet.setType(FirebirdSQLInfoReturnValue.SELECT);
+ ShardingSphereColumn column = new ShardingSphereColumn("col", Types.INTEGER, false, false, false, true, false, true);
+ ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singleton(column), Collections.emptyList(), Collections.emptyList());
+ FirebirdReturnColumnPacket columnPacket =
+ new FirebirdReturnColumnPacket(Collections.singleton(FirebirdSQLInfoPacketType.DESCRIBE_END), 1, table, column, "", "", "");
+ packet.getDescribeSelect().add(columnPacket);
+ packet.getDescribeBind().add(columnPacket);
+ packet.write(payload);
+ verify(payload).writeInt1(FirebirdSQLInfoPacketType.STMT_TYPE.getCode());
+ verify(payload).writeInt1(FirebirdCommonInfoPacketType.END.getCode());
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdReturnColumnPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdReturnColumnPacketTest.java
new file mode 100644
index 00000000000..07f54e90ecb
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/statement/prepare/FirebirdReturnColumnPacketTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.db.protocol.firebird.packet.command.query.statement.prepare;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdReturnColumnPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertWrite() {
+ ShardingSphereColumn column = new ShardingSphereColumn("col", Types.INTEGER, false, false, false, true, false, true);
+ ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singleton(column), Collections.emptyList(), Collections.emptyList());
+ FirebirdReturnColumnPacket packet = new FirebirdReturnColumnPacket(Arrays.asList(
+ FirebirdSQLInfoPacketType.SQLDA_SEQ,
+ FirebirdSQLInfoPacketType.TYPE,
+ FirebirdSQLInfoPacketType.SUB_TYPE,
+ FirebirdSQLInfoPacketType.SCALE,
+ FirebirdSQLInfoPacketType.LENGTH,
+ FirebirdSQLInfoPacketType.FIELD,
+ FirebirdSQLInfoPacketType.ALIAS,
+ FirebirdSQLInfoPacketType.RELATION,
+ FirebirdSQLInfoPacketType.RELATION_ALIAS,
+ FirebirdSQLInfoPacketType.OWNER,
+ FirebirdSQLInfoPacketType.DESCRIBE_END), 1, table, column, "t", "c", "o");
+ when(payload.getCharset()).thenReturn(java.nio.charset.StandardCharsets.UTF_8);
+ packet.write(payload);
+ verify(payload).writeInt1(FirebirdSQLInfoPacketType.SQLDA_SEQ.getCode());
+ verify(payload).writeInt1(FirebirdSQLInfoPacketType.DESCRIBE_END.getCode());
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdCommitTransactionPacketTest.java
similarity index 51%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdCommitTransactionPacketTest.java
index 438c76058f7..e256e8ecf47 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdCommitTransactionPacketTest.java
@@ -15,19 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-class FirebirdProtocolDefaultVersionProviderTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdCommitTransactionPacketTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertReadTransactionId() {
+ when(payload.readInt4()).thenReturn(123);
+ FirebirdCommitTransactionPacket packet = new FirebirdCommitTransactionPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getTransactionId(), is(123));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(FirebirdCommitTransactionPacket.getLength(), is(8));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdRollbackTransactionPacketTest.java
similarity index 51%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdRollbackTransactionPacketTest.java
index 438c76058f7..641af89cfe5 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/command/query/transaction/FirebirdRollbackTransactionPacketTest.java
@@ -15,19 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-class FirebirdProtocolDefaultVersionProviderTest {
+@ExtendWith(MockitoExtension.class)
+class FirebirdRollbackTransactionPacketTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Mock
+ private FirebirdPacketPayload payload;
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertReadTransactionId() {
+ when(payload.readInt4()).thenReturn(456);
+ FirebirdRollbackTransactionPacket packet = new FirebirdRollbackTransactionPacket(payload);
+ verify(payload).skipReserved(4);
+ assertThat(packet.getTransactionId(), is(456));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(FirebirdRollbackTransactionPacket.getLength(), is(8));
}
}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
new file mode 100644
index 00000000000..8cd825075bf
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.db.protocol.firebird.packet.generic;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.binary.BinaryCell;
+import org.apache.shardingsphere.db.protocol.binary.BinaryRow;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.FirebirdBinaryProtocolValue;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.FirebirdBinaryProtocolValueFactory;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.firebirdsql.gds.ISCConstants;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mockStatic;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFetchResponsePacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private FirebirdBinaryProtocolValue protocolValue;
+
+ @Test
+ void assertWriteWithRow() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.writerIndex()).thenReturn(0);
+ when(byteBuf.writeZero(4)).thenReturn(byteBuf);
+ BinaryRow row = new BinaryRow(Collections.singleton(new BinaryCell(FirebirdBinaryColumnType.LONG, 123)));
+ try (MockedStatic<FirebirdBinaryProtocolValueFactory> mocked = mockStatic(FirebirdBinaryProtocolValueFactory.class)) {
+ mocked.when(() -> FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.LONG)).thenReturn(protocolValue);
+ FirebirdFetchResponsePacket packet = new FirebirdFetchResponsePacket(row);
+ packet.write(payload);
+ verify(payload).writeInt4(FirebirdCommandPacketType.FETCH_RESPONSE.getValue());
+ verify(payload).writeInt4(ISCConstants.FETCH_OK);
+ verify(payload).writeInt4(1);
+ verify(byteBuf).writeZero(4);
+ verify(protocolValue).write(payload, 123);
+ }
+ }
+
+ @Test
+ void assertWriteWithoutRow() {
+ FirebirdFetchResponsePacket packet = new FirebirdFetchResponsePacket();
+ packet.write(payload);
+ verify(payload).writeInt4(FirebirdCommandPacketType.FETCH_RESPONSE.getValue());
+ verify(payload).writeInt4(ISCConstants.FETCH_NO_MORE_ROWS);
+ verify(payload).writeInt4(0);
+ verify(payload, never()).getByteBuf();
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdGenericResponsePacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdGenericResponsePacketTest.java
new file mode 100644
index 00000000000..111b3a7f928
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdGenericResponsePacketTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.db.protocol.firebird.packet.generic;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.err.FirebirdStatusVector;
+import org.apache.shardingsphere.db.protocol.firebird.packet.FirebirdPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.firebirdsql.gds.ISCConstants;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.lang.reflect.Field;
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdGenericResponsePacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private FirebirdPacket data;
+
+ @Mock
+ private FirebirdStatusVector vector;
+
+ @Test
+ void assertGetHandleAndId() {
+ FirebirdGenericResponsePacket packet = FirebirdGenericResponsePacket.getPacket().setHandle(1).setId(2);
+ assertThat(packet.getHandle(), is(1));
+ assertThat(packet.getId(), is(2L));
+ }
+
+ @Test
+ void assertGetErrorStatusVector() {
+ SQLException ex = new SQLException("foo", "42000", ISCConstants.isc_random + 1);
+ FirebirdGenericResponsePacket packet = new FirebirdGenericResponsePacket().setErrorStatusVector(ex);
+ assertThat(packet.getErrorCode(), is(ex.getErrorCode()));
+ assertThat(packet.getErrorMessage(), is("foo"));
+ }
+
+ @Test
+ void assertWriteWithoutData() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ new FirebirdGenericResponsePacket().setHandle(3).setId(4).write(payload);
+ verify(payload).writeInt4(FirebirdCommandPacketType.RESPONSE.getValue());
+ verify(payload).writeInt4(3);
+ verify(payload).writeInt8(4L);
+ verify(payload).writeInt4(0);
+ verify(byteBuf).writeZero(4);
+ }
+
+ @Test
+ void assertWriteWithDataAndStatusVector() throws ReflectiveOperationException {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.writeZero(4)).thenReturn(byteBuf);
+ when(byteBuf.readableBytes()).thenReturn(4, 8);
+ FirebirdGenericResponsePacket packet = new FirebirdGenericResponsePacket().setHandle(1).setId(2).setData(data);
+ Field field = FirebirdGenericResponsePacket.class.getDeclaredField("statusVector");
+ field.setAccessible(true);
+ field.set(packet, vector);
+ packet.write(payload);
+ verify(data).write(payload);
+ verify(vector).write(payload);
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdSQLResponsePacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdSQLResponsePacketTest.java
new file mode 100644
index 00000000000..ec786ffa0ea
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/generic/FirebirdSQLResponsePacketTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.db.protocol.firebird.packet.generic;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.binary.BinaryCell;
+import org.apache.shardingsphere.db.protocol.binary.BinaryRow;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.FirebirdBinaryProtocolValue;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.protocol.FirebirdBinaryProtocolValueFactory;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mockStatic;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdSQLResponsePacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private FirebirdBinaryProtocolValue protocolValue;
+
+ @Test
+ void assertWriteWithRow() {
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.writerIndex()).thenReturn(0);
+ when(byteBuf.writeZero(4)).thenReturn(byteBuf);
+ BinaryRow row = new BinaryRow(Collections.singleton(new BinaryCell(FirebirdBinaryColumnType.LONG, 5)));
+ try (MockedStatic<FirebirdBinaryProtocolValueFactory> mocked = mockStatic(FirebirdBinaryProtocolValueFactory.class)) {
+ mocked.when(() -> FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.LONG)).thenReturn(protocolValue);
+ FirebirdSQLResponsePacket packet = new FirebirdSQLResponsePacket(row);
+ packet.write(payload);
+ verify(payload).writeInt4(FirebirdCommandPacketType.SQL_RESPONSE.getValue());
+ verify(payload).writeInt4(1);
+ verify(byteBuf).writeZero(4);
+ verify(protocolValue).write(payload, 5);
+ }
+ }
+
+ @Test
+ void assertWriteWithoutRow() {
+ FirebirdSQLResponsePacket packet = new FirebirdSQLResponsePacket();
+ packet.write(payload);
+ verify(payload).writeInt4(FirebirdCommandPacketType.SQL_RESPONSE.getValue());
+ verify(payload).writeInt4(0);
+ verify(payload, never()).getByteBuf();
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptDataPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptDataPacketTest.java
new file mode 100644
index 00000000000..2a875c18dcf
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptDataPacketTest.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.db.protocol.firebird.packet.handshake;
+
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdAuthenticationMethod;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.inOrder;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdAcceptDataPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertWriteWithData() {
+ byte[] salt = {1, 2};
+ String publicKey = "key";
+ FirebirdAcceptDataPacket packet = new FirebirdAcceptDataPacket(salt, publicKey,
+ FirebirdAuthenticationMethod.SRP, 1, "k");
+ packet.write(payload);
+ verify(payload).writeInt4(salt.length + publicKey.length() + 4);
+ verify(payload).writeInt2LE(salt.length);
+ verify(payload).writeBytes(salt);
+ verify(payload).writeInt2LE(publicKey.length());
+ verify(payload).writeBytes(publicKey.getBytes(StandardCharsets.US_ASCII));
+ verify(payload).writeString("Srp");
+ verify(payload).writeInt4(1);
+ verify(payload).writeString("k");
+ }
+
+ @Test
+ void assertWriteWithoutData() {
+ FirebirdAcceptDataPacket packet = new FirebirdAcceptDataPacket(new byte[0], "", FirebirdAuthenticationMethod.SRP, 0, "");
+ packet.write(payload);
+ InOrder order = inOrder(payload);
+ order.verify(payload).writeInt4(0);
+ order.verify(payload).writeString("Srp");
+ order.verify(payload).writeInt4(0);
+ order.verify(payload).writeString("");
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java
new file mode 100644
index 00000000000..7aa897dd069
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAcceptPacketTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.db.protocol.firebird.packet.handshake;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdArchType;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdAuthenticationMethod;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocol;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdAcceptPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertAcceptPacket() {
+ when(byteBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
+ ByteBuf buf2 = mock(ByteBuf.class);
+ when(buf2.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 2);
+ List<FirebirdProtocol> list = new ArrayList<>();
+ list.add(new FirebirdProtocol(byteBuf));
+ list.add(new FirebirdProtocol(buf2));
+ FirebirdAcceptPacket packet = new FirebirdAcceptPacket(list);
+ assertEquals(FirebirdCommandPacketType.ACCEPT, packet.getOpCode());
+ assertThat(packet.getProtocol().getWeight(), is(2));
+ }
+
+ @Test
+ void assertWriteWithAcceptDataPacket() {
+ when(byteBuf.readInt()).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode(), FirebirdArchType.ARCH_GENERIC.getCode(), 0, 5, 1);
+ List<FirebirdProtocol> list = new ArrayList<>();
+ list.add(new FirebirdProtocol(byteBuf));
+ FirebirdAcceptPacket packet = new FirebirdAcceptPacket(list);
+ packet.setAcceptDataPacket(new byte[0], "", FirebirdAuthenticationMethod.SRP, 0, "");
+ InOrder io = inOrder(payload);
+ packet.write(payload);
+ io.verify(payload).writeInt4(FirebirdCommandPacketType.ACCEPT_DATA.getValue());
+ io.verify(payload).writeInt4(FirebirdProtocolVersion.PROTOCOL_VERSION11.getCode());
+ io.verify(payload).writeInt4(FirebirdArchType.ARCH_GENERIC.getCode());
+ io.verify(payload).writeInt4(5);
+ io.verify(payload).writeInt4(0);
+ io.verify(payload).writeString("Srp");
+ io.verify(payload).writeInt4(0);
+ io.verify(payload).writeString("");
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
new file mode 100644
index 00000000000..a49b835c372
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdAttachPacketTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.db.protocol.firebird.packet.handshake;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.constant.buffer.type.FirebirdDatabaseParameterBufferType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdAttachPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertAttachPacket() {
+ when(payload.readInt4()).thenReturn(100);
+ when(payload.readString()).thenReturn("db");
+ ByteBuf dpb = mock(ByteBuf.class);
+ when(payload.readBuffer()).thenReturn(dpb);
+ when(dpb.readUnsignedByte()).thenReturn(
+ (short) 1,
+ (short) FirebirdDatabaseParameterBufferType.LC_CTYPE.getCode(),
+ (short) FirebirdDatabaseParameterBufferType.SPECIFIC_AUTH_DATA.getCode(),
+ (short) FirebirdDatabaseParameterBufferType.USER_NAME.getCode(),
+ (short) FirebirdDatabaseParameterBufferType.PASSWORD_ENC.getCode());
+ when(dpb.isReadable()).thenReturn(true, true, true, true, false);
+ when(dpb.readByte()).thenReturn((byte) 4, (byte) 2, (byte) 4, (byte) 6);
+ ByteBuf slice1 = mock(ByteBuf.class);
+ when(slice1.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("UTF8");
+ ByteBuf slice2 = mock(ByteBuf.class);
+ when(slice2.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("ad");
+ ByteBuf slice3 = mock(ByteBuf.class);
+ when(slice3.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("user");
+ ByteBuf slice4 = mock(ByteBuf.class);
+ when(slice4.toString(java.nio.charset.StandardCharsets.UTF_8)).thenReturn("passwd");
+ when(dpb.readSlice(anyInt())).thenReturn(slice1, slice2, slice3, slice4);
+ FirebirdAttachPacket packet = new FirebirdAttachPacket(payload);
+ assertEquals(100, packet.getId());
+ assertThat(packet.getDatabase(), is("db"));
+ assertThat(packet.getEncoding(), is("UTF8"));
+ assertThat(packet.getAuthData(), is("ad"));
+ assertThat(packet.getUsername(), is("user"));
+ assertThat(packet.getEncPassword(), is("passwd"));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
new file mode 100644
index 00000000000..aa408da9344
--- /dev/null
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.db.protocol.firebird.packet.handshake;
+
+import io.netty.buffer.ByteBuf;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdArchType;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdAuthenticationMethod;
+import org.apache.shardingsphere.db.protocol.firebird.constant.FirebirdUserDataType;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocol;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdConnectPacketTest {
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Test
+ void assertConnectPacket() {
+ ByteBuf userInfo = mock(ByteBuf.class);
+ ByteBuf userBuf = mock(ByteBuf.class);
+ ByteBuf pluginBuf = mock(ByteBuf.class);
+ ByteBuf specBuf1 = mock(ByteBuf.class);
+ ByteBuf specBuf2 = mock(ByteBuf.class);
+ ByteBuf protocolBuf = mock(ByteBuf.class);
+ when(payload.readInt4()).thenReturn(
+ FirebirdCommandPacketType.CONNECT.getValue(),
+ 1,
+ FirebirdArchType.ARCH_GENERIC.getCode(),
+ 1);
+ when(payload.readString()).thenReturn("db");
+ when(payload.readBuffer()).thenReturn(userInfo);
+ when(payload.getByteBuf()).thenReturn(protocolBuf);
+ when(userInfo.isReadable()).thenReturn(true, true, true, true, false);
+ when(userInfo.readUnsignedByte()).thenReturn(
+ (short) FirebirdUserDataType.CNCT_USER.getCode(), (short) 4,
+ (short) FirebirdUserDataType.CNCT_PLUGIN_NAME.getCode(), (short) 3,
+ (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), (short) 2,
+ (short) FirebirdUserDataType.CNCT_SPECIFIC_DATA.getCode(), (short) 2);
+ when(userInfo.readSlice(4)).thenReturn(userBuf);
+ when(userInfo.readSlice(3)).thenReturn(pluginBuf);
+ when(userInfo.readSlice(2)).thenReturn(specBuf1, specBuf2);
+ when(userBuf.toString(StandardCharsets.UTF_8)).thenReturn("user");
+ when(pluginBuf.toString(StandardCharsets.UTF_8)).thenReturn("srp");
+ when(specBuf1.readUnsignedByte()).thenReturn((short) 0);
+ when(specBuf1.toString(StandardCharsets.US_ASCII)).thenReturn("A");
+ when(specBuf2.readUnsignedByte()).thenReturn((short) 1);
+ when(specBuf2.toString(StandardCharsets.US_ASCII)).thenReturn("B");
+ when(protocolBuf.readInt()).thenReturn(
+ FirebirdProtocolVersion.PROTOCOL_VERSION10.getCode(),
+ FirebirdArchType.ARCH_GENERIC.getCode(),
+ 0, 5, 1);
+ FirebirdConnectPacket packet = new FirebirdConnectPacket(payload);
+ assertEquals(FirebirdCommandPacketType.CONNECT, packet.getOpCode());
+ assertThat(packet.getConnectVersion(), is(1));
+ assertThat(packet.getArchType(), is(FirebirdArchType.ARCH_GENERIC));
+ assertThat(packet.getDatabase(), is("db"));
+ assertThat(packet.getProtocolsCount(), is(1));
+ assertThat(packet.getUsername(), is("user"));
+ assertThat(packet.getPluginName(), is("srp"));
+ assertThat(packet.getPlugin(), is(FirebirdAuthenticationMethod.SRP));
+ assertThat(packet.getAuthData(), is("AB"));
+ List<FirebirdProtocol> protocols = packet.getUserProtocols();
+ assertThat(protocols.size(), is(1));
+ assertThat(protocols.get(0).getVersion(), is(FirebirdProtocolVersion.PROTOCOL_VERSION10));
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
similarity index 57%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
index 438c76058f7..3fa5883c1d5 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
@@ -15,19 +15,33 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.db.protocol.firebird.packet.handshake;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
-class FirebirdProtocolDefaultVersionProviderTest {
+class FirebirdSRPAuthenticationDataTest {
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+ @Test
+ void assertNormalizeLoginUppercase() {
+ assertThat(FirebirdSRPAuthenticationData.normalizeLogin("abc"), is("ABC"));
+ }
+
+ @Test
+ void assertNormalizeLoginQuoted() {
+ assertThat(FirebirdSRPAuthenticationData.normalizeLogin("\"Ab\"\"c\""), is("Ab\"c"));
+ }
+
+ @Test
+ void assertNormalizeLoginNull() {
+ assertNull(FirebirdSRPAuthenticationData.normalizeLogin(null));
+ }
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertNormalizeLoginEmpty() {
+ assertThat(FirebirdSRPAuthenticationData.normalizeLogin(""), is(""));
}
}
diff --git a/proxy/frontend/type/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngine.java b/proxy/frontend/type/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngine.java
index 369bd1148ba..0135ea23139 100644
--- a/proxy/frontend/type/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngine.java
+++ b/proxy/frontend/type/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngine.java
@@ -46,7 +46,7 @@ public final class FirebirdFrontendEngine implements DatabaseProtocolFrontendEng
public void release(final ConnectionSession connectionSession) {
FirebirdStatementIdGenerator.getInstance().unregisterConnection(connectionSession.getConnectionId());
FirebirdTransactionIdGenerator.getInstance().unregisterConnection(connectionSession.getConnectionId());
- FirebirdConnectionProtocolVersion.getInstance().unregisterConnection(connectionSession.getConnectionId());
+ FirebirdConnectionProtocolVersion.getInstance().unsetProtocolVersion(connectionSession.getConnectionId());
}
@Override
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java
index b43e025c961..fa622c062a2 100644
--- a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java
@@ -27,8 +27,8 @@ import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -36,6 +36,9 @@ import static org.mockito.Mockito.when;
@StaticMockSettings({ProxyContext.class, FirebirdStatementIdGenerator.class, FirebirdTransactionIdGenerator.class, FirebirdConnectionProtocolVersion.class})
class FirebirdFrontendEngineTest {
+ @Mock
+ private ConnectionSession connectionSession;
+
private FirebirdFrontendEngine engine;
@BeforeEach
@@ -45,12 +48,11 @@ class FirebirdFrontendEngineTest {
@Test
void assertRelease() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
int connectionId = 1;
when(connectionSession.getConnectionId()).thenReturn(connectionId);
engine.release(connectionSession);
verify(FirebirdStatementIdGenerator.getInstance()).unregisterConnection(connectionId);
verify(FirebirdTransactionIdGenerator.getInstance()).unregisterConnection(connectionId);
- verify(FirebirdConnectionProtocolVersion.getInstance()).unregisterConnection(connectionId);
+ verify(FirebirdConnectionProtocolVersion.getInstance()).unsetProtocolVersion(connectionId);
}
}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/FirebirdAuthenticationEngineTest.java
similarity index 52%
copy from proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java
copy to proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/FirebirdAuthenticationEngineTest.java
index b43e025c961..f1a5b9f8b03 100644
--- a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/FirebirdFrontendEngineTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/FirebirdAuthenticationEngineTest.java
@@ -15,42 +15,43 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.frontend.firebird;
+package org.apache.shardingsphere.proxy.frontend.firebird.authentication;
-import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdConnectionProtocolVersion;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import io.netty.channel.ChannelHandlerContext;
+import org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator;
import org.apache.shardingsphere.proxy.frontend.firebird.command.query.statement.FirebirdStatementIdGenerator;
import org.apache.shardingsphere.proxy.frontend.firebird.command.query.transaction.FirebirdTransactionIdGenerator;
import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
-import static org.mockito.Mockito.mock;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings({ProxyContext.class, FirebirdStatementIdGenerator.class, FirebirdTransactionIdGenerator.class, FirebirdConnectionProtocolVersion.class})
-class FirebirdFrontendEngineTest {
+@StaticMockSettings({ConnectionIdGenerator.class, FirebirdTransactionIdGenerator.class, FirebirdStatementIdGenerator.class})
+class FirebirdAuthenticationEngineTest {
- private FirebirdFrontendEngine engine;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ChannelHandlerContext context;
- @BeforeEach
- void setUp() {
- engine = new FirebirdFrontendEngine();
- }
+ @Mock
+ private ConnectionIdGenerator idGenerator;
@Test
- void assertRelease() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
- int connectionId = 1;
- when(connectionSession.getConnectionId()).thenReturn(connectionId);
- engine.release(connectionSession);
- verify(FirebirdStatementIdGenerator.getInstance()).unregisterConnection(connectionId);
- verify(FirebirdTransactionIdGenerator.getInstance()).unregisterConnection(connectionId);
- verify(FirebirdConnectionProtocolVersion.getInstance()).unregisterConnection(connectionId);
+ void assertHandshake() {
+ when(ConnectionIdGenerator.getInstance()).thenReturn(idGenerator);
+ when(idGenerator.nextId()).thenReturn(1);
+ FirebirdAuthenticationEngine engine = new FirebirdAuthenticationEngine();
+ assertThat(engine.handshake(context), is(1));
+ verify(FirebirdTransactionIdGenerator.getInstance()).registerConnection(1);
+ verify(FirebirdStatementIdGenerator.getInstance()).registerConnection(1);
}
+
+ // TODO Implement tests for authenticate() method for the following cases: CONNECT, ATTACH, Cont_Auth (when implemented), Unknown Option
}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/FirebirdAuthenticatorTypeTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/FirebirdAuthenticatorTypeTest.java
index f9732b4e0b4..c5dd53a87e3 100644
--- a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/FirebirdAuthenticatorTypeTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/FirebirdAuthenticatorTypeTest.java
@@ -21,30 +21,37 @@ import org.apache.shardingsphere.authentication.Authenticator;
import org.apache.shardingsphere.authentication.AuthenticatorFactory;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@ExtendWith(MockitoExtension.class)
class FirebirdAuthenticatorTypeTest {
- private final AuthorityRule rule = mock(AuthorityRule.class);
+ @Mock
+ private AuthorityRule rule;
+
+ @Mock
+ private ShardingSphereUser shardingsphereUser;
@ParameterizedTest(name = "{0}")
@ArgumentsSource(TestCaseArgumentsProvider.class)
void assertAuthenticator(final String name, final String authenticatorType, final String expectedAuthenticatorClassName) {
when(rule.getAuthenticatorType(any())).thenReturn(authenticatorType);
- Authenticator actual = new AuthenticatorFactory<>(FirebirdAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
+ Authenticator actual = new AuthenticatorFactory<>(FirebirdAuthenticatorType.class, rule).newInstance(shardingsphereUser);
assertThat(actual.getClass().getSimpleName(), is(expectedAuthenticatorClassName));
}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdLegacyAuthenticatorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdLegacyAuthenticatorTest.java
new file mode 100644
index 00000000000..92a12f3440b
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdLegacyAuthenticatorTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.proxy.frontend.firebird.authentication.authenticator.impl;
+
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.junit.jupiter.api.Test;
+import org.firebirdsql.gds.ng.wire.auth.legacy.UnixCrypt;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class FirebirdLegacyAuthenticatorTest {
+
+ private final FirebirdLegacyAuthenticator authenticator = new FirebirdLegacyAuthenticator();
+
+ @Test
+ void assertAuthenticationMethodName() {
+ assertThat(authenticator.getAuthenticationMethodName(), is("Legacy_Auth"));
+ }
+
+ @Test
+ void assertAuthenticateSuccess() {
+ ShardingSphereUser user = new ShardingSphereUser("foo", "password", "");
+ String expectedPassword = UnixCrypt.crypt(user.getPassword(), "9z").substring(2, 13);
+ assertTrue(authenticator.authenticate(user, new Object[]{expectedPassword}));
+ }
+
+ @Test
+ void assertAuthenticateFailure() {
+ ShardingSphereUser user = new ShardingSphereUser("foo", "password", "");
+ assertFalse(authenticator.authenticate(user, new Object[]{"wrong"}));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdSRPAuthenticatorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdSRPAuthenticatorTest.java
new file mode 100644
index 00000000000..e9fe8b4f2b9
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/authenticator/impl/FirebirdSRPAuthenticatorTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.proxy.frontend.firebird.authentication.authenticator.impl;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.handshake.FirebirdSRPAuthenticationData;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.firebirdsql.util.ByteArrayHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class FirebirdSRPAuthenticatorTest {
+
+ private final FirebirdSRPAuthenticator authenticator = new FirebirdSRPAuthenticator();
+
+ @Test
+ void assertAuthenticationMethodName() {
+ assertThat(authenticator.getAuthenticationMethodName(), is("Srp"));
+ }
+
+ @Test
+ void assertAuthenticateSuccess() {
+ ShardingSphereUser user = new ShardingSphereUser("foo", "password", "");
+ FirebirdSRPAuthenticationData authData = new FirebirdSRPAuthenticationData("SHA-1", user.getGrantee().getUsername(), user.getPassword(), "4");
+ String clientProof = ByteArrayHelper.toHexString(authData.serverProof(user.getGrantee().getUsername()));
+ assertTrue(authenticator.authenticate(user, new Object[]{null, authData, clientProof}));
+ }
+
+ @Test
+ void assertAuthenticateFailure() {
+ ShardingSphereUser user = new ShardingSphereUser("foo", "password", "");
+ FirebirdSRPAuthenticationData authData = new FirebirdSRPAuthenticationData("SHA-1", user.getGrantee().getUsername(), user.getPassword(), "4");
+ assertFalse(authenticator.authenticate(user, new Object[]{null, authData, "wrong"}));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/FirebirdCommandExecuteEngineTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/FirebirdCommandExecuteEngineTest.java
new file mode 100644
index 00000000000..a254768b333
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/FirebirdCommandExecuteEngineTest.java
@@ -0,0 +1,172 @@
+/*
+ * 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.proxy.frontend.firebird.command;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdConnectionProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.constant.protocol.FirebirdProtocolVersion;
+import org.apache.shardingsphere.db.protocol.firebird.packet.FirebirdPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketFactory;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.FirebirdCommandPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.payload.FirebirdPacketPayload;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.db.protocol.packet.command.CommandPacket;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
+import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionResourceLock;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
+import org.apache.shardingsphere.proxy.frontend.firebird.err.FirebirdErrorPacketFactory;
+import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
+import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.nio.charset.StandardCharsets;
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+@StaticMockSettings({
+ FirebirdCommandPacketFactory.class,
+ FirebirdConnectionProtocolVersion.class,
+ FirebirdCommandExecutorFactory.class,
+ FirebirdErrorPacketFactory.class,
+ ProxyContext.class
+})
+class FirebirdCommandExecuteEngineTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private ChannelHandlerContext context;
+
+ @Mock
+ private Channel channel;
+
+ @Mock
+ private QueryCommandExecutor queryCommandExecutor;
+
+ @Mock
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
+
+ @Mock
+ private FirebirdPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Mock
+ private FirebirdConnectionProtocolVersion connectionProtocolVersion;
+
+ @Mock
+ private CommandExecutor executor;
+
+ @Mock
+ private CommandPacket packet;
+
+ @Mock
+ private ConnectionResourceLock connectionResourceLock;
+
+ @Mock
+ private ContextManager mockContextManager;
+
+ @Mock
+ private FirebirdPacket errorPacket;
+
+ @Mock
+ private FirebirdCommandPacket commandPacket;
+
+ @Mock
+ private DatabasePacket rowPacket;
+
+ private FirebirdCommandExecuteEngine engine;
+
+ @BeforeEach
+ void setUp() {
+ engine = new FirebirdCommandExecuteEngine();
+ when(context.channel()).thenReturn(channel);
+ }
+
+ @Test
+ void assertGetCommandPacketType() {
+ when(byteBuf.readerIndex()).thenReturn(0);
+ when(byteBuf.getInt(0)).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue());
+ FirebirdPacketPayload payload = new FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8);
+ assertThat(engine.getCommandPacketType(payload), is(FirebirdCommandPacketType.EXECUTE));
+ }
+
+ @Test
+ void assertGetCommandPacket() {
+ when(connectionSession.getConnectionId()).thenReturn(1);
+ when(FirebirdConnectionProtocolVersion.getInstance()).thenReturn(connectionProtocolVersion);
+ when(connectionProtocolVersion.getProtocolVersion(1)).thenReturn(FirebirdProtocolVersion.PROTOCOL_VERSION10);
+ when(FirebirdCommandPacketFactory.newInstance(FirebirdCommandPacketType.EXECUTE, payload, FirebirdProtocolVersion.PROTOCOL_VERSION10)).thenReturn(commandPacket);
+ assertThat(engine.getCommandPacket(payload, FirebirdCommandPacketType.EXECUTE, connectionSession), is(commandPacket));
+ }
+
+ @Test
+ void assertGetCommandExecutor() throws SQLException {
+ when(FirebirdCommandExecutorFactory.newInstance(FirebirdCommandPacketType.EXECUTE, packet, connectionSession)).thenReturn(executor);
+ assertThat(engine.getCommandExecutor(FirebirdCommandPacketType.EXECUTE, packet, connectionSession), is(executor));
+ }
+
+ @Test
+ void assertGetErrorPacket() {
+ Exception cause = new Exception("error");
+ when(FirebirdErrorPacketFactory.newInstance(cause)).thenReturn(errorPacket);
+ assertThat(engine.getErrorPacket(cause), is(errorPacket));
+ }
+
+ @Test
+ void assertWriteQueryData() throws SQLException {
+ when(databaseConnectionManager.getConnectionResourceLock()).thenReturn(connectionResourceLock);
+ when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.QUERY);
+ when(channel.isActive()).thenReturn(true);
+ when(queryCommandExecutor.next()).thenReturn(true, false);
+ when(queryCommandExecutor.getQueryRowPacket()).thenReturn(rowPacket);
+ MetaDataContexts metaDataContexts =
+ new MetaDataContexts(new ShardingSphereMetaData(), new ShardingSphereStatistics());
+ when(mockContextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
+ when(ProxyContext.getInstance().getContextManager()).thenReturn(mockContextManager);
+ engine.writeQueryData(context, databaseConnectionManager, queryCommandExecutor, 0);
+ verify(connectionResourceLock).doAwait(context);
+ verify(context).write(rowPacket);
+ verify(context).flush();
+ }
+}
diff --git a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/admin/FirebirdUnsupportedCommandExecutorTest.java
similarity index 64%
copy from db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
copy to proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/admin/FirebirdUnsupportedCommandExecutorTest.java
index 438c76058f7..9c025674108 100644
--- a/db-protocol/firebird/src/test/java/org/apache/shardingsphere/db/protocol/firebird/constant/FirebirdProtocolDefaultVersionProviderTest.java
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/admin/FirebirdUnsupportedCommandExecutorTest.java
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.firebird.constant;
+package org.apache.shardingsphere.proxy.frontend.firebird.command.admin;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-class FirebirdProtocolDefaultVersionProviderTest {
-
- private final FirebirdProtocolDefaultVersionProvider provider = new FirebirdProtocolDefaultVersionProvider();
+class FirebirdUnsupportedCommandExecutorTest {
@Test
- void assertGetDatabaseTypeReturnsFirebird() {
- assertThat(provider.getDatabaseType(), is("Firebird"));
+ void assertExecute() {
+ FirebirdUnsupportedCommandExecutor executor = new FirebirdUnsupportedCommandExecutor();
+ assertThat(executor.execute().iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
}
}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdDatabaseInfoExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdDatabaseInfoExecutorTest.java
new file mode 100644
index 00000000000..255b968b82a
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdDatabaseInfoExecutorTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.info;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.FirebirdInfoPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.database.FirebirdDatabaseInfoReturnPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdDatabaseInfoExecutorTest {
+
+ @Mock
+ private FirebirdInfoPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Test
+ void assertExecute() {
+ when(packet.getInfoItems()).thenReturn(Collections.emptyList());
+ FirebirdDatabaseInfoExecutor executor = new FirebirdDatabaseInfoExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket responsePacket = (FirebirdGenericResponsePacket) actual.iterator().next();
+ assertThat(responsePacket.getData(), instanceOf(FirebirdDatabaseInfoReturnPacket.class));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdSQLInfoExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdSQLInfoExecutorTest.java
new file mode 100644
index 00000000000..595915b9654
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/info/FirebirdSQLInfoExecutorTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.info;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.FirebirdInfoPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoReturnPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdSQLInfoExecutorTest {
+
+ @Mock
+ private FirebirdInfoPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Test
+ void assertExecute() {
+ when(packet.getInfoItems()).thenReturn(Collections.emptyList());
+ FirebirdSQLInfoExecutor executor = new FirebirdSQLInfoExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ FirebirdGenericResponsePacket responsePacket = (FirebirdGenericResponsePacket) actual.iterator().next();
+ assertThat(responsePacket.getData(), instanceOf(FirebirdSQLInfoReturnPacket.class));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java
new file mode 100644
index 00000000000..22a808f987c
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdAllocateStatementCommandExecutorTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.statement;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdAllocateStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdAllocateStatementCommandExecutorTest {
+
+ private static final int CONNECTION_ID = 1;
+
+ @Mock
+ private FirebirdAllocateStatementPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @BeforeEach
+ void setup() {
+ FirebirdStatementIdGenerator.getInstance().registerConnection(CONNECTION_ID);
+ when(connectionSession.getConnectionId()).thenReturn(CONNECTION_ID);
+ }
+
+ @AfterEach
+ void tearDown() {
+ FirebirdStatementIdGenerator.getInstance().unregisterConnection(CONNECTION_ID);
+ }
+
+ @Test
+ void assertExecute() throws SQLException {
+ FirebirdAllocateStatementCommandExecutor executor = new FirebirdAllocateStatementCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertEquals(1, actual.size());
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ assertEquals(1, ((FirebirdGenericResponsePacket) actual.iterator().next()).getHandle());
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFetchStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFetchStatementCommandExecutorTest.java
new file mode 100644
index 00000000000..5464bd05257
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFetchStatementCommandExecutorTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.statement;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdFetchStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdFetchResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFetchStatementCommandExecutorTest {
+
+ @Mock
+ private FirebirdFetchStatementPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Test
+ void assertExecute() throws SQLException {
+ FirebirdFetchStatementCommandExecutor executor = new FirebirdFetchStatementCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdFetchResponsePacket.class));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFreeStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFreeStatementCommandExecutorTest.java
new file mode 100644
index 00000000000..eee0e866589
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/FirebirdFreeStatementCommandExecutorTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.statement;
+
+import org.apache.shardingsphere.db.protocol.firebird.exception.FirebirdProtocolException;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.FirebirdFreeStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatementRegistry;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdFreeStatementCommandExecutorTest {
+
+ @Mock
+ private FirebirdFreeStatementPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private ServerPreparedStatementRegistry registry;
+
+ @Test
+ void assertExecuteWithDrop() throws SQLException {
+ when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(registry);
+ when(packet.getOption()).thenReturn(FirebirdFreeStatementPacket.DROP);
+ when(packet.getStatementId()).thenReturn(1);
+ FirebirdFreeStatementCommandExecutor executor = new FirebirdFreeStatementCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ verify(registry).removePreparedStatement(1);
+ }
+
+ @Test
+ void assertExecuteWithUnprepare() throws SQLException {
+ when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(registry);
+ when(packet.getOption()).thenReturn(FirebirdFreeStatementPacket.UNPREPARE);
+ when(packet.getStatementId()).thenReturn(1);
+ FirebirdFreeStatementCommandExecutor executor = new FirebirdFreeStatementCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ verify(registry).removePreparedStatement(1);
+ }
+
+ @Test
+ void assertExecuteWithClose() throws SQLException {
+ when(packet.getOption()).thenReturn(FirebirdFreeStatementPacket.CLOSE);
+ FirebirdFreeStatementCommandExecutor executor = new FirebirdFreeStatementCommandExecutor(packet, connectionSession);
+ executor.execute();
+ verify(connectionSession.getConnectionContext()).clearCursorContext();
+ }
+
+ @Test
+ void assertExecuteWithUnknownOption() {
+ when(packet.getOption()).thenReturn(999);
+ FirebirdFreeStatementCommandExecutor executor = new FirebirdFreeStatementCommandExecutor(packet, connectionSession);
+ assertThrows(FirebirdProtocolException.class, executor::execute);
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/execute/FirebirdExecuteStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/execute/FirebirdExecuteStatementCommandExecutorTest.java
new file mode 100644
index 00000000000..f25e980eca3
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/execute/FirebirdExecuteStatementCommandExecutorTest.java
@@ -0,0 +1,150 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.statement.execute;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.FirebirdPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.execute.FirebirdExecuteStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdFetchResponsePacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdSQLResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.hint.HintValueContext;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
+import org.apache.shardingsphere.infra.session.query.QueryContext;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
+import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
+import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
+import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
+import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
+import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatementRegistry;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
+import org.apache.shardingsphere.proxy.frontend.firebird.command.query.FirebirdServerPreparedStatement;
+import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
+import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings({ProxyBackendHandlerFactory.class, ProxyContext.class})
+@MockitoSettings(strictness = Strictness.LENIENT)
+class FirebirdExecuteStatementCommandExecutorTest {
+
+ private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "Firebird");
+
+ @Mock
+ private FirebirdExecuteStatementPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private ProxyBackendHandler proxyBackendHandler;
+
+ @Mock
+ private ConnectionContext connectionContext;
+
+ @Mock
+ private QueryHeader queryHeader;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private UpdateStatementContext updateContext;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private SelectStatementContext selectContext;
+
+ @BeforeEach
+ void setUp() {
+ ServerPreparedStatementRegistry registry = new ServerPreparedStatementRegistry();
+ when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(registry);
+ when(connectionSession.getConnectionContext()).thenReturn(connectionContext);
+ when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData()).thenReturn(new ShardingSphereMetaData());
+ when(selectContext.getSqlStatement()).thenReturn(new org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement(databaseType));
+ registry.addPreparedStatement(1, new FirebirdServerPreparedStatement("SELECT * FROM tbl", selectContext, new HintValueContext()));
+ when(updateContext.getSqlStatement()).thenReturn(new org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement(databaseType));
+ registry.addPreparedStatement(2, new FirebirdServerPreparedStatement("UPDATE tbl SET col=1", updateContext, new HintValueContext()));
+ }
+
+ @Test
+ void assertIsQueryResponse() throws SQLException {
+ when(packet.getStatementId()).thenReturn(1);
+ when(packet.getParameterTypes()).thenReturn(Collections.emptyList());
+ when(packet.getParameterValues()).thenReturn(new ArrayList<>());
+ when(packet.isStoredProcedure()).thenReturn(true);
+ FirebirdExecuteStatementCommandExecutor executor = new FirebirdExecuteStatementCommandExecutor(packet, connectionSession);
+ when(proxyBackendHandler.execute()).thenReturn(new QueryResponseHeader(Collections.singletonList(queryHeader)));
+ when(proxyBackendHandler.next()).thenReturn(true, true);
+ QueryResponseRow row = new QueryResponseRow(Collections.singletonList(new QueryResponseCell(Types.INTEGER, 1)));
+ when(proxyBackendHandler.getRowData()).thenReturn(row, row);
+ when(ProxyBackendHandlerFactory.newInstance(eq(databaseType), any(QueryContext.class), eq(connectionSession), eq(true))).thenReturn(proxyBackendHandler);
+ Collection<DatabasePacket> actual = executor.execute();
+ Iterator<DatabasePacket> iterator = actual.iterator();
+ assertThat(executor.getResponseType(), is(ResponseType.QUERY));
+ assertThat(iterator.next(), instanceOf(FirebirdSQLResponsePacket.class));
+ assertThat(iterator.next(), instanceOf(FirebirdGenericResponsePacket.class));
+ assertFalse(iterator.hasNext());
+ assertTrue(executor.next());
+ FirebirdPacket rowPacket = executor.getQueryRowPacket();
+ assertThat(rowPacket, instanceOf(FirebirdFetchResponsePacket.class));
+ executor.close();
+ verify(proxyBackendHandler).close();
+ }
+
+ @Test
+ void assertIsUpdateResponse() throws SQLException {
+ when(packet.getStatementId()).thenReturn(2);
+ when(packet.getParameterTypes()).thenReturn(Collections.emptyList());
+ when(packet.getParameterValues()).thenReturn(new ArrayList<>());
+ FirebirdExecuteStatementCommandExecutor executor = new FirebirdExecuteStatementCommandExecutor(packet, connectionSession);
+ when(proxyBackendHandler.execute()).thenReturn(new UpdateResponseHeader(new org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement(databaseType)));
+ when(ProxyBackendHandlerFactory.newInstance(eq(databaseType), any(QueryContext.class), eq(connectionSession), eq(true))).thenReturn(proxyBackendHandler);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(executor.getResponseType(), is(ResponseType.UPDATE));
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
new file mode 100644
index 00000000000..dadc558caa1
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.statement.prepare;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoPacketType;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.info.type.sql.FirebirdSQLInfoReturnValue;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.prepare.FirebirdPrepareStatementPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.statement.prepare.FirebirdPrepareStatementReturnPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.hint.HintValueContext;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.parser.rule.SQLParserRule;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatementRegistry;
+import org.apache.shardingsphere.proxy.frontend.firebird.command.query.FirebirdServerPreparedStatement;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
+import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Collections;
+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.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings(ProxyContext.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class FirebirdPrepareStatementCommandExecutorTest {
+
+ private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "Firebird");
+
+ @Mock
+ private FirebirdPrepareStatementPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @BeforeEach
+ void setUp() {
+ when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(new ServerPreparedStatementRegistry());
+ when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db");
+ when(packet.getSQL()).thenReturn("SELECT 1");
+ when(packet.getHintValueContext()).thenReturn(new HintValueContext());
+ when(packet.isValidStatementHandle()).thenReturn(true);
+ when(packet.getStatementId()).thenReturn(1);
+ when(packet.nextItem()).thenReturn(true, false);
+ when(packet.getCurrentItem()).thenReturn(FirebirdSQLInfoPacketType.STMT_TYPE);
+ SQLParserRule parserRule = new SQLParserRule(new SQLParserRuleConfiguration(new CacheOption(128, 1024L), new CacheOption(128, 1024L)));
+ RuleMetaData globalRuleMetaData = new RuleMetaData(Collections.singleton(parserRule));
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", Collections.emptyList(), Collections.emptyList());
+ ShardingSphereDatabase database =
+ new ShardingSphereDatabase("foo_db", databaseType, new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+ ShardingSphereMetaData metaData =
+ new ShardingSphereMetaData(Collections.singleton(database), new ResourceMetaData(Collections.emptyMap()), globalRuleMetaData, new ConfigurationProperties(new Properties()));
+ MetaDataContexts metaDataContexts = new MetaDataContexts(metaData, new ShardingSphereStatistics());
+ when(ProxyContext.getInstance().getContextManager().getMetaDataContexts()).thenReturn(metaDataContexts);
+ }
+
+ @Test
+ void assertExecute() throws SQLException {
+ FirebirdPrepareStatementCommandExecutor executor = new FirebirdPrepareStatementCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ FirebirdGenericResponsePacket responsePacket = (FirebirdGenericResponsePacket) actual.iterator().next();
+ FirebirdPrepareStatementReturnPacket returnPacket = (FirebirdPrepareStatementReturnPacket) responsePacket.getData();
+ assertThat(returnPacket.getType(), is(FirebirdSQLInfoReturnValue.SELECT));
+ FirebirdServerPreparedStatement preparedStatement = connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(1);
+ assertThat(preparedStatement.getSql(), is("SELECT 1"));
+ assertThat(preparedStatement.getSqlStatementContext(), instanceOf(SelectStatementContext.class));
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdCommitTransactionCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdCommitTransactionCommandExecutorTest.java
new file mode 100644
index 00000000000..0c4f0d99e89
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdCommitTransactionCommandExecutorTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.transaction;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdCommitTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.MockedConstruction;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mockConstruction;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdCommitTransactionCommandExecutorTest {
+
+ @Mock
+ private FirebirdCommitTransactionPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Test
+ void assertExecute() throws SQLException {
+ when(connectionSession.isAutoCommit()).thenReturn(false);
+ try (MockedConstruction<BackendTransactionManager> mocked = mockConstruction(BackendTransactionManager.class, (mock, context) -> {
+ })) {
+ FirebirdCommitTransactionCommandExecutor executor = new FirebirdCommitTransactionCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ verify(mocked.constructed().get(0)).commit();
+ }
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdRollbackTransactionCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdRollbackTransactionCommandExecutorTest.java
new file mode 100644
index 00000000000..1e503a90bb6
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdRollbackTransactionCommandExecutorTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.transaction;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdRollbackTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockedConstruction;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdRollbackTransactionCommandExecutorTest {
+
+ @Mock
+ private FirebirdRollbackTransactionPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @Test
+ void assertExecute() throws SQLException {
+ when(connectionSession.isAutoCommit()).thenReturn(false);
+ try (MockedConstruction<BackendTransactionManager> mocked = mockConstruction(BackendTransactionManager.class, (mock, context) -> {
+ })) {
+ FirebirdRollbackTransactionCommandExecutor executor = new FirebirdRollbackTransactionCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ assertThat(actual.iterator().next(), instanceOf(FirebirdGenericResponsePacket.class));
+ verify(mocked.constructed().get(0)).rollback();
+ }
+ }
+}
diff --git a/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
new file mode 100644
index 00000000000..61182265946
--- /dev/null
+++ b/proxy/frontend/type/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/transaction/FirebirdStartTransactionCommandExecutorTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.proxy.frontend.firebird.command.query.transaction;
+
+import org.apache.shardingsphere.db.protocol.firebird.packet.command.query.transaction.FirebirdStartTransactionPacket;
+import org.apache.shardingsphere.db.protocol.firebird.packet.generic.FirebirdGenericResponsePacket;
+import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class FirebirdStartTransactionCommandExecutorTest {
+
+ private static final int CONNECTION_ID = 1;
+
+ @Mock
+ private FirebirdStartTransactionPacket packet;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ @BeforeEach
+ void setup() {
+ FirebirdTransactionIdGenerator.getInstance().registerConnection(CONNECTION_ID);
+ when(connectionSession.getConnectionId()).thenReturn(CONNECTION_ID);
+ }
+
+ @AfterEach
+ void tearDown() {
+ FirebirdTransactionIdGenerator.getInstance().unregisterConnection(CONNECTION_ID);
+ }
+
+ @Test
+ void assertExecute() throws SQLException {
+ when(packet.getAutocommit()).thenReturn(true);
+ when(packet.getReadOnly()).thenReturn(true);
+ when(packet.getIsolationLevel()).thenReturn(TransactionIsolationLevel.SERIALIZABLE);
+ FirebirdStartTransactionCommandExecutor executor = new FirebirdStartTransactionCommandExecutor(packet, connectionSession);
+ Collection<DatabasePacket> actual = executor.execute();
+ DatabasePacket first = actual.iterator().next();
+ assertThat(first, instanceOf(FirebirdGenericResponsePacket.class));
+ assertEquals(1, ((FirebirdGenericResponsePacket) first).getHandle());
+ verify(connectionSession).setAutoCommit(true);
+ verify(connectionSession).setReadOnly(true);
+ verify(connectionSession).setIsolationLevel(TransactionIsolationLevel.SERIALIZABLE);
+ }
+}