You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/12/06 16:54:47 UTC
[shardingsphere] branch master updated: Add test cases for GenericSQLException (#22707)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 c217637752a Add test cases for GenericSQLException (#22707)
c217637752a is described below
commit c217637752a9c036a7972c9d4b4fd0c9ba58f78a
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Dec 7 00:54:40 2022 +0800
Add test cases for GenericSQLException (#22707)
---
.../generic/DatabaseProtocolSQLExceptionTest.java | 37 ++++++++++++++++++++++
.../sql/type/generic/UnknownSQLExceptionTest.java | 37 ++++++++++++++++++++++
.../UnsupportedSQLOperationExceptionTest.java | 37 ++++++++++++++++++++++
3 files changed, 111 insertions(+)
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLExceptionTest.java
new file mode 100644
index 00000000000..afde09c8629
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLExceptionTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.infra.util.exception.external.sql.type.generic;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.junit.Test;
+
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class DatabaseProtocolSQLExceptionTest {
+
+ @Test
+ public void assertToSQLException() {
+ SQLException actual = new DatabaseProtocolSQLException("foo_reason").toSQLException();
+ assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
+ assertThat(actual.getErrorCode(), is(30002));
+ assertThat(actual.getMessage(), is("Database protocol exception: foo_reason"));
+ }
+}
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnknownSQLExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnknownSQLExceptionTest.java
new file mode 100644
index 00000000000..9c738bad65e
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnknownSQLExceptionTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.infra.util.exception.external.sql.type.generic;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.junit.Test;
+
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class UnknownSQLExceptionTest {
+
+ @Test
+ public void assertToSQLException() {
+ SQLException actual = new UnknownSQLException(new RuntimeException("foo_reason")).toSQLException();
+ assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
+ assertThat(actual.getErrorCode(), is(30000));
+ assertThat(actual.getMessage(), is("Unknown exception: foo_reason"));
+ }
+}
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnsupportedSQLOperationExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnsupportedSQLOperationExceptionTest.java
new file mode 100644
index 00000000000..b535526dfc6
--- /dev/null
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/UnsupportedSQLOperationExceptionTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.infra.util.exception.external.sql.type.generic;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.junit.Test;
+
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class UnsupportedSQLOperationExceptionTest {
+
+ @Test
+ public void assertToSQLException() {
+ SQLException actual = new UnsupportedSQLOperationException("foo_reason").toSQLException();
+ assertThat(actual.getSQLState(), is(XOpenSQLState.FEATURE_NOT_SUPPORTED.getValue()));
+ assertThat(actual.getErrorCode(), is(30001));
+ assertThat(actual.getMessage(), is("Unsupported SQL operation: foo_reason"));
+ }
+}