This is an automated email from the ASF dual-hosted git repository.

zhangyonglun 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 45d0cc1  add test cases (#7030)
45d0cc1 is described below

commit 45d0cc11b441163338c03eb5cb4d648006e39113
Author: Yanjie Zhou <[email protected]>
AuthorDate: Mon Aug 24 21:12:21 2020 +0800

    add test cases (#7030)
    
    * add test cases
    
    * add test cases
    
    * add test cases
---
 .../PostgreSQLInt2BinaryProtocolValueTest.java     | 47 ++++++++++++
 .../PostgreSQLInt4BinaryProtocolValueTest.java     | 47 ++++++++++++
 .../PostgreSQLInt8BinaryProtocolValueTest.java     | 47 ++++++++++++
 .../PostgreSQLStringBinaryProtocolValueTest.java   | 66 +++++++++++++++++
 .../PostgreSQLTimeBinaryProtocolValueTest.java     | 50 +++++++++++++
 .../describe/PostgreSQLComDescribePacketTest.java  | 45 +++++++++++
 .../execute/PostgreSQLComExecutePacketTest.java    | 45 +++++++++++
 .../binary/parse/PostgreSQLComParsePacketTest.java | 59 +++++++++++++++
 .../parse/PostgreSQLParseCompletePacketTest.java   | 35 +++++++++
 .../binary/sync/PostgreSQLComSyncPacketTest.java   | 43 +++++++++++
 .../query/text/PostgreSQLComQueryPacketTest.java   | 47 ++++++++++++
 .../query/text/PostgreSQLDataRowPacketTest.java    | 86 ++++++++++++++++++++++
 12 files changed, 617 insertions(+)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
new file mode 100644
index 0000000..35645ee
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.postgresql.packet.command.query.binary.bind.protocol;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLInt2BinaryProtocolValueTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLInt2BinaryProtocolValue actual = new 
PostgreSQLInt2BinaryProtocolValue();
+        assertThat(actual.getColumnLength(null), equalTo(2));
+        when(payload.readInt2()).thenReturn(1);
+        assertThat(actual.read(payload), is(1));
+        actual.write(payload, 1);
+        verify(payload).writeInt2(1);
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
new file mode 100644
index 0000000..de0423d
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.postgresql.packet.command.query.binary.bind.protocol;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLInt4BinaryProtocolValueTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLInt4BinaryProtocolValue actual = new 
PostgreSQLInt4BinaryProtocolValue();
+        assertThat(actual.getColumnLength(null), equalTo(4));
+        when(payload.readInt4()).thenReturn(1);
+        assertThat(actual.read(payload), is(1));
+        actual.write(payload, 1);
+        verify(payload).writeInt4(1);
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
new file mode 100644
index 0000000..447293f
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.postgresql.packet.command.query.binary.bind.protocol;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLInt8BinaryProtocolValueTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLInt8BinaryProtocolValue actual = new 
PostgreSQLInt8BinaryProtocolValue();
+        assertThat(actual.getColumnLength(null), equalTo(8));
+        when(payload.readInt8()).thenReturn(1L);
+        assertThat(actual.read(payload), is(1L));
+        actual.write(payload, 1L);
+        verify(payload).writeInt8(1L);
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringBinaryProtocolValueTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringBinaryProtocolValueTest.java
new file mode 100644
index 0000000..ee49bd6
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringBinaryProtocolValueTest.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.postgresql.packet.command.query.binary.bind.protocol;
+
+import io.netty.buffer.ByteBuf;
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLStringBinaryProtocolValueTest {
+    
+    @InjectMocks
+    private PostgreSQLPacketPayload payload;
+    
+    @Mock
+    private ByteBuf byteBuf;
+    
+    @Test
+    public void assertNewInstance() {
+        when(byteBuf.readerIndex()).thenReturn(8);
+        doAnswer(new Answer<ByteBuf>() {
+            @Override
+            public ByteBuf answer(final InvocationOnMock invocation) throws 
Throwable {
+                ((byte[]) invocation.getArguments()[0])[0] = 97;
+                return byteBuf;
+            }
+        }).when(byteBuf).readBytes(any(byte[].class));
+        PostgreSQLStringBinaryProtocolValue actual = new 
PostgreSQLStringBinaryProtocolValue();
+        assertThat(actual.getColumnLength("str"), equalTo("str".length()));
+        when(payload.readInt4()).thenReturn(1);
+        assertThat(actual.read(payload), equalTo("a"));
+        verify(byteBuf).readerIndex(4);
+        actual.write(payload, "a");
+        verify(byteBuf).writeBytes("a".getBytes());
+        actual.write(payload, new byte[1]);
+        verify(byteBuf).writeBytes(new byte[1]);
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.java
new file mode 100644
index 0000000..c1582ed
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.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.postgresql.packet.command.query.binary.bind.protocol;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.sql.Timestamp;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLTimeBinaryProtocolValueTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLTimeBinaryProtocolValue actual = new 
PostgreSQLTimeBinaryProtocolValue();
+        assertThat(actual.getColumnLength(null), equalTo(8));
+        when(payload.readInt8()).thenReturn(1L);
+        assertThat(actual.read(payload), is(1L));
+        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
+        actual.write(payload, timestamp);
+        verify(payload).writeInt8(timestamp.getTime());
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacketTest.java
new file mode 100644
index 0000000..2f3393a
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacketTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.postgresql.packet.command.query.binary.describe;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLComDescribePacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLComDescribePacket actual = new 
PostgreSQLComDescribePacket(payload);
+        actual.write(payload);
+        assertThat(actual.getMessageType(), is('D'));
+        verify(payload).readInt4();
+        verify(payload).readInt1();
+        verify(payload).readStringNul();
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/execute/PostgreSQLComExecutePacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/execute/PostgreSQLComExecutePacketTest.java
new file mode 100644
index 0000000..227b9dd
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/execute/PostgreSQLComExecutePacketTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.postgresql.packet.command.query.binary.execute;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLComExecutePacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLComExecutePacket actual = new 
PostgreSQLComExecutePacket(payload);
+        verify(payload, atLeast(2)).readInt4();
+        verify(payload).readStringNul();
+        actual.write(payload);
+        assertThat(actual.getMessageType(), is('E'));
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacketTest.java
new file mode 100644
index 0000000..665fcc2
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacketTest.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.postgresql.packet.command.query.binary.parse;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLColumnType;
+import 
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.PostgreSQLBinaryStatementParameterType;
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLComParsePacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        when(payload.readInt2()).thenReturn(1);
+        when(payload.readInt4()).thenReturn(0);
+        when(payload.readStringNul()).thenReturn("sql");
+        PostgreSQLComParsePacket actual = new 
PostgreSQLComParsePacket(payload);
+        actual.write(payload);
+        assertThat(actual.getMessageType(), is('P'));
+        assertThat(actual.getSql(), is("sql"));
+        assertThat(actual.getStatementId(), is("sql"));
+        List<PostgreSQLBinaryStatementParameterType> types = 
actual.getBinaryStatementParameterTypes();
+        assertNotNull(types);
+        assertThat(types.size(), equalTo(1));
+        assertThat(types.get(0).getColumnType(), 
is(PostgreSQLColumnType.POSTGRESQL_TYPE_UNSPECIFIED));
+        
assertTrue(actual.toString().startsWith("PostgreSQLComParsePacket(statementId=sql,
 sql=sql, binaryStatementParameterTypes=["));
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacketTest.java
new file mode 100644
index 0000000..d316716
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacketTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.postgresql.packet.command.query.binary.parse;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class PostgreSQLParseCompletePacketTest {
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLParseCompletePacket actual = new 
PostgreSQLParseCompletePacket();
+        actual.write(mock(PostgreSQLPacketPayload.class));
+        assertThat(actual.getMessageType(), is('1'));
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/sync/PostgreSQLComSyncPacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/sync/PostgreSQLComSyncPacketTest.java
new file mode 100644
index 0000000..5bdb005
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/sync/PostgreSQLComSyncPacketTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.postgresql.packet.command.query.binary.sync;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLComSyncPacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        PostgreSQLComSyncPacket actual = new PostgreSQLComSyncPacket(payload);
+        actual.write(payload);
+        verify(payload).readInt4();
+        assertThat(actual.getMessageType(), is('S'));
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacketTest.java
new file mode 100644
index 0000000..68b7640
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacketTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.postgresql.packet.command.query.text;
+
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLComQueryPacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Test
+    public void assertNewInstance() {
+        when(payload.readStringNul()).thenReturn("sql");
+        PostgreSQLComQueryPacket actual = new 
PostgreSQLComQueryPacket(payload);
+        actual.write(payload);
+        verify(payload).readInt4();
+        assertThat(actual.getSql(), is("sql"));
+        assertThat(actual.getMessageType(), is('Q'));
+        assertThat(actual.toString(), is("PostgreSQLComQueryPacket(sql=sql)"));
+    }
+}
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacketTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacketTest.java
new file mode 100644
index 0000000..7bbe296
--- /dev/null
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacketTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.postgresql.packet.command.query.text;
+
+import lombok.SneakyThrows;
+import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class PostgreSQLDataRowPacketTest {
+    
+    @Mock
+    private PostgreSQLPacketPayload payload;
+    
+    @Mock
+    private SQLXML sqlxml;
+    
+    @Test
+    public void assertWriteWithNull() {
+        PostgreSQLDataRowPacket actual = new 
PostgreSQLDataRowPacket(Collections.singletonList(null));
+        actual.write(payload);
+        verify(payload).writeInt4(0xFFFFFFFF);
+    }
+    
+    @Test
+    public void assertWriteWithBytes() {
+        PostgreSQLDataRowPacket actual = new 
PostgreSQLDataRowPacket(Collections.singletonList(new byte[]{'a'}));
+        actual.write(payload);
+        verify(payload).writeInt4(new byte[]{'a'}.length);
+        verify(payload).writeBytes(new byte[]{'a'});
+    }
+    
+    @Test
+    @SneakyThrows
+    public void assertWriteWithSQLXML() {
+        when(sqlxml.getString()).thenReturn("string");
+        PostgreSQLDataRowPacket actual = new 
PostgreSQLDataRowPacket(Collections.singletonList(sqlxml));
+        actual.write(payload);
+        verify(payload).writeInt4("string".getBytes().length);
+        verify(payload).writeStringEOF("string");
+    }
+    
+    @Test
+    public void assertWriteWithString() {
+        PostgreSQLDataRowPacket actual = new 
PostgreSQLDataRowPacket(Collections.singletonList("str"));
+        assertThat(actual.getData(), is(Collections.singletonList("str")));
+        actual.write(payload);
+        verify(payload).writeInt4("str".getBytes().length);
+        verify(payload).writeStringEOF("str");
+    }
+    
+    @Test
+    @SneakyThrows
+    public void assertWriteWithSQLXML4Error() {
+        when(sqlxml.getString()).thenThrow(new SQLException("mock"));
+        PostgreSQLDataRowPacket actual = new 
PostgreSQLDataRowPacket(Collections.singletonList(sqlxml));
+        actual.write(payload);
+    }
+}

Reply via email to