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 8f044782099 Add more test cases on FirebirdExecuteStatementPacketTest 
(#38172)
8f044782099 is described below

commit 8f0447820999704193a464c05fae5e2255a0c71a
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 23 23:43:44 2026 +0800

    Add more test cases on FirebirdExecuteStatementPacketTest (#38172)
---
 .../FirebirdExecuteStatementPacketTest.java        | 94 +++++++++++++++++-----
 1 file changed, 75 insertions(+), 19 deletions(-)

diff --git 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
index a88e31bd71f..9b48733d150 100644
--- 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
+++ 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
@@ -22,21 +22,25 @@ import 
org.apache.shardingsphere.database.protocol.firebird.constant.protocol.Fi
 import 
org.apache.shardingsphere.database.protocol.firebird.packet.command.FirebirdCommandPacketType;
 import 
org.apache.shardingsphere.database.protocol.firebird.packet.command.query.FirebirdBinaryColumnType;
 import 
org.apache.shardingsphere.database.protocol.firebird.payload.FirebirdPacketPayload;
+import org.apache.shardingsphere.database.protocol.payload.PacketPayload;
 import org.firebirdsql.gds.BlrConstants;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import java.util.Collections;
+import java.util.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.hamcrest.Matchers.is;
 import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 
 @ExtendWith(MockitoExtension.class)
@@ -48,28 +52,48 @@ class FirebirdExecuteStatementPacketTest {
     @Mock
     private ByteBuf byteBuf;
     
-    @Test
-    void assertExecuteStatementPacket() {
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("assertExecuteStatementPacketArguments")
+    void assertExecuteStatementPacket(final String name, final short blrType, 
final FirebirdBinaryColumnType expectedParameterType, final Object 
expectedParameterValue) {
         
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.readUnsignedByte()).thenReturn((short) 5, (short) 0, 
blrType, (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(expectedParameterType)));
+        assertThat(packet.getParameterValues(), 
is(Collections.singletonList(expectedParameterValue)));
+    }
+    
+    @Test
+    void assertExecuteStatementPacketWithNullParameterValue() {
+        when(payload.readInt1()).thenReturn(1);
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(),
 1, 2, 0, 1);
+        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.getParameterTypes(), 
is(Collections.singletonList(FirebirdBinaryColumnType.LONG)));
-        assertThat(packet.getParameterValues(), 
is(Collections.singletonList(123)));
+        assertThat(packet.getParameterValues(), 
is(Collections.singletonList(null)));
+    }
+    
+    @Test
+    void assertExecuteStatementPacketWhenBLRIsNotReadable() {
+        when(payload.readBuffer()).thenReturn(byteBuf);
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(),
 1, 2, 0, 0);
+        FirebirdExecuteStatementPacket packet = new 
FirebirdExecuteStatementPacket(payload, 
FirebirdProtocolVersion.PROTOCOL_VERSION13);
+        assertThat(packet.getParameterTypes(), is(Collections.emptyList()));
+        assertThat(packet.getParameterValues(), is(Collections.emptyList()));
     }
     
     @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());
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE2.getValue(),
 1, 2, 0, 1, 123, 9);
         ByteBuf returnBlr = mock(ByteBuf.class);
         when(payload.readBuffer()).thenReturn(byteBuf, returnBlr);
         when(byteBuf.isReadable()).thenReturn(true);
@@ -80,7 +104,6 @@ class FirebirdExecuteStatementPacketTest {
         when(returnBlr.skipBytes(anyInt())).thenReturn(returnBlr);
         when(payload.readInt4Unsigned()).thenReturn(30L, 1L, 1024L);
         FirebirdExecuteStatementPacket packet = new 
FirebirdExecuteStatementPacket(payload, 
FirebirdProtocolVersion.PROTOCOL_VERSION19);
-        assertTrue(packet.isStoredProcedure());
         assertThat(packet.getReturnColumns(), 
is(Collections.singletonList(FirebirdBinaryColumnType.LONG)));
         assertThat(packet.getOutputMessageNumber(), is(9));
         assertThat(packet.getParameterValues(), 
is(Collections.singletonList(123)));
@@ -89,19 +112,52 @@ class FirebirdExecuteStatementPacketTest {
         assertThat(packet.getMaxBlobSize(), is(1024L));
     }
     
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("assertIsStoredProcedureArguments")
+    void assertIsStoredProcedure(final String name, final 
FirebirdCommandPacketType commandPacketType, final boolean 
expectedStoredProcedure) {
+        when(payload.readInt4()).thenReturn(commandPacketType.getValue(), 1, 
2, 0, 0);
+        when(payload.readBuffer()).thenReturn(byteBuf);
+        FirebirdExecuteStatementPacket packet = new 
FirebirdExecuteStatementPacket(payload, 
FirebirdProtocolVersion.PROTOCOL_VERSION13);
+        assertThat(packet.isStoredProcedure(), is(expectedStoredProcedure));
+    }
+    
+    @Test
+    void assertWrite() {
+        when(payload.readBuffer()).thenReturn(byteBuf);
+        
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(),
 1, 2, 0, 0);
+        FirebirdExecuteStatementPacket packet = new 
FirebirdExecuteStatementPacket(payload, 
FirebirdProtocolVersion.PROTOCOL_VERSION13);
+        FirebirdPacketPayload writePayload = mock(FirebirdPacketPayload.class);
+        packet.write((PacketPayload) writePayload);
+        verifyNoInteractions(writePayload);
+    }
+    
     @Test
     void assertGetLength() {
+        when(payload.getByteBuf()).thenReturn(byteBuf);
         
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(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);
         when(byteBuf.readerIndex()).thenReturn(42);
         assertThat(FirebirdExecuteStatementPacket.getLength(payload, 
FirebirdProtocolVersion.PROTOCOL_VERSION13), is(42));
         verify(byteBuf).resetReaderIndex();
     }
+    
+    private static Stream<Arguments> assertExecuteStatementPacketArguments() {
+        return Stream.of(
+                Arguments.of("skip_count_4", (short) 
BlrConstants.blr_varying2, FirebirdBinaryColumnType.VARYING, null),
+                Arguments.of("skip_count_2", (short) BlrConstants.blr_text, 
FirebirdBinaryColumnType.LEGACY_TEXT, null),
+                Arguments.of("skip_count_1", (short) BlrConstants.blr_long, 
FirebirdBinaryColumnType.LONG, 123),
+                Arguments.of("skip_count_0", (short) BlrConstants.blr_bool, 
FirebirdBinaryColumnType.BOOLEAN, 0),
+                Arguments.of("blob_parameter", (short) BlrConstants.blr_quad, 
FirebirdBinaryColumnType.BLOB, 0L));
+    }
+    
+    private static Stream<Arguments> assertIsStoredProcedureArguments() {
+        return Stream.of(
+                Arguments.of("execute", FirebirdCommandPacketType.EXECUTE, 
false),
+                Arguments.of("execute2", FirebirdCommandPacketType.EXECUTE2, 
true),
+                Arguments.of("fetch", FirebirdCommandPacketType.FETCH, false));
+    }
 }

Reply via email to