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 d0e81e83b12 Add test case for SQLExceptionTransformEngine (#28147)
d0e81e83b12 is described below
commit d0e81e83b12a008911c9a35e0cbd3e9302d4d1f3
Author: kk <[email protected]>
AuthorDate: Fri Aug 18 15:10:17 2023 +0800
Add test case for SQLExceptionTransformEngine (#28147)
* Add test case for SQLExceptionTransformEngine
* modify DatabaseType find
* modify comment
* fix checkstytle
---------
Co-authored-by: 80597928 <[email protected]>
---
.../dialect/SQLExceptionTransformEngineTest.java | 44 ++++++++++++++++++++++
.../DatabaseProtocolExceptionExceptionFixture.java | 27 +++++++++++++
.../fixture/SQLDialectExceptionMapperFixture.java | 36 ++++++++++++++++++
...eption.dialect.mapper.SQLDialectExceptionMapper | 18 +++++++++
4 files changed, 125 insertions(+)
diff --git
a/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
new file mode 100644
index 00000000000..b372fa88045
--- /dev/null
+++
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngineTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.exception.dialect;
+
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.DatabaseCreateExistsException;
+import
org.apache.shardingsphere.infra.exception.dialect.fixture.DatabaseProtocolExceptionExceptionFixture;
+import
org.apache.shardingsphere.infra.hint.SQLHintDataSourceNotExistsException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class SQLExceptionTransformEngineTest {
+
+ @Test
+ void assertSQLExceptionTransformEngineConvertException() {
+ assertThat(SQLException.class,
is(SQLExceptionTransformEngine.toSQLException(new SQLException(),
null).getClass()));
+ assertThat(SQLException.class,
is(SQLExceptionTransformEngine.toSQLException(new
SQLHintDataSourceNotExistsException("only for test"), null).getClass()));
+ assertThat(SQLException.class,
+ is(SQLExceptionTransformEngine.toSQLException(new
DatabaseProtocolExceptionExceptionFixture("only for test"),
TypedSPILoader.getService(DatabaseType.class, "MySQL")).getClass()));
+ assertThat(SQLException.class,
+ is(SQLExceptionTransformEngine.toSQLException(new
DatabaseCreateExistsException("only for test"),
TypedSPILoader.getService(DatabaseType.class, "MySQL")).getClass()));
+ assertThat(SQLException.class,
is(SQLExceptionTransformEngine.toSQLException(new RuntimeException("only for
test"), null).getClass()));
+ }
+}
diff --git
a/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/DatabaseProtocolExceptionExceptionFixture.java
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/DatabaseProtocolExceptionExceptionFixture.java
new file mode 100644
index 00000000000..ac29f25dbf6
--- /dev/null
+++
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/DatabaseProtocolExceptionExceptionFixture.java
@@ -0,0 +1,27 @@
+/*
+ * 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.exception.dialect.fixture;
+
+import
org.apache.shardingsphere.infra.exception.dialect.exception.protocol.DatabaseProtocolException;
+
+public final class DatabaseProtocolExceptionExceptionFixture extends
DatabaseProtocolException {
+
+ public DatabaseProtocolExceptionExceptionFixture(final String reason) {
+ super(reason);
+ }
+}
diff --git
a/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/SQLDialectExceptionMapperFixture.java
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/SQLDialectExceptionMapperFixture.java
new file mode 100644
index 00000000000..c0187a0ba09
--- /dev/null
+++
b/infra/exception/dialect/core/src/test/java/org/apache/shardingsphere/infra/exception/dialect/fixture/SQLDialectExceptionMapperFixture.java
@@ -0,0 +1,36 @@
+/*
+ * 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.exception.dialect.fixture;
+
+import
org.apache.shardingsphere.infra.exception.dialect.exception.SQLDialectException;
+import
org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper;
+
+import java.sql.SQLException;
+
+public final class SQLDialectExceptionMapperFixture implements
SQLDialectExceptionMapper {
+
+ @Override
+ public SQLException convert(final SQLDialectException sqlDialectException)
{
+ return new SQLException("only for test");
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "MySQL";
+ }
+}
diff --git
a/infra/exception/dialect/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper
b/infra/exception/dialect/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper
new file mode 100644
index 00000000000..50ecded00b7
--- /dev/null
+++
b/infra/exception/dialect/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.exception.dialect.fixture.SQLDialectExceptionMapperFixture