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/11/09 06:02:09 UTC
[shardingsphere] branch master updated: Add strategy for loading SQL cases with GitHub, Gitee, and local (#22030)
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 a01e9bdf281 Add strategy for loading SQL cases with GitHub, Gitee, and local (#22030)
a01e9bdf281 is described below
commit a01e9bdf281374c33dfb5d746a5089da09e5a9b7
Author: Junfeng <i...@jacob953.com>
AuthorDate: Wed Nov 9 14:02:02 2022 +0800
Add strategy for loading SQL cases with GitHub, Gitee, and local (#22030)
* feat: add interface DynamicLoadingSQLCaseLoaderStrategyIT
* feat: add loader of GitHub
* feat: add loader of Gitee
* feat: add loader of Local
* feat: modify style of code with checkstyle
* fix: replace null with empty string on initail
* fix: replace null with empty string on empty result
* feat: rename classes in package loader to avoid IT
Co-authored-by: Jacob953 <ja...@csu.edu.cn>
---
.../parser/loader/DynamicSQLCaseGitHubLoader.java | 53 ++++++++++++++++++++++
.../parser/loader/DynamicSQLCaseGiteeLoader.java | 53 ++++++++++++++++++++++
.../loader/DynamicSQLCaseLoaderStrategy.java | 33 ++++++++++++++
.../parser/loader/DynamicSQLCaseLocalLoader.java | 48 ++++++++++++++++++++
4 files changed, 187 insertions(+)
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGitHubLoader.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGitHubLoader.java
new file mode 100644
index 00000000000..83fbcd3e075
--- /dev/null
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGitHubLoader.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.sql.parser.loader;
+
+import org.apache.shardingsphere.sql.parser.base.DynamicLoadingSQLParserParameterizedTest;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
+public class DynamicSQLCaseGitHubLoader extends DynamicLoadingSQLParserParameterizedTest implements DynamicSQLCaseLoaderStrategy {
+
+ public DynamicSQLCaseGitHubLoader() {
+ super("", "", "", new CSVResultGenerator(""));
+ }
+
+ /**
+ * Get test parameters.
+ *
+ * @param sqlCaseURI the URI of sql case
+ *
+ * @return Test cases from GitHub.
+ **/
+ public Collection<Object[]> getTestParameters(final URI sqlCaseURI) {
+ Collection<Object[]> result = new LinkedList<>();
+ for (Map<String, String> each : getResponse("https://api.github.com/repos/", sqlCaseURI)) {
+ String sqlCaseFileName = each.get("name").split("\\.")[0];
+ String sqlCaseFileContent = getContent(URI.create(each.get("download_url")));
+ result.addAll(getSQLCases(sqlCaseFileName, sqlCaseFileContent));
+ }
+ if (result.isEmpty()) {
+ result.add(new Object[]{"", ""});
+ }
+ return result;
+ }
+}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGiteeLoader.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGiteeLoader.java
new file mode 100644
index 00000000000..66b1edc6bb3
--- /dev/null
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseGiteeLoader.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.sql.parser.loader;
+
+import org.apache.shardingsphere.sql.parser.base.DynamicLoadingSQLParserParameterizedTest;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
+public class DynamicSQLCaseGiteeLoader extends DynamicLoadingSQLParserParameterizedTest implements DynamicSQLCaseLoaderStrategy {
+
+ public DynamicSQLCaseGiteeLoader() {
+ super("", "", "", new CSVResultGenerator(""));
+ }
+
+ /**
+ * Get test parameters.
+ *
+ * @param sqlCaseURI the URI of sql case
+ *
+ * @return Test cases from Gitee.
+ **/
+ public Collection<Object[]> getTestParameters(final URI sqlCaseURI) {
+ Collection<Object[]> result = new LinkedList<>();
+ for (Map<String, String> each : getResponse("https://gitee.com/api/v5/repos/", sqlCaseURI)) {
+ String sqlCaseFileName = each.get("name").split("\\.")[0];
+ String sqlCaseFileContent = getContent(URI.create(each.get("download_url")));
+ result.addAll(getSQLCases(sqlCaseFileName, sqlCaseFileContent));
+ }
+ if (result.isEmpty()) {
+ result.add(new Object[]{"", ""});
+ }
+ return result;
+ }
+}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLoaderStrategy.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLoaderStrategy.java
new file mode 100644
index 00000000000..5c6ba2c4f30
--- /dev/null
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLoaderStrategy.java
@@ -0,0 +1,33 @@
+/*
+ * 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.sql.parser.loader;
+
+import java.net.URI;
+import java.util.Collection;
+
+public interface DynamicSQLCaseLoaderStrategy {
+
+ /**
+ * Get test parameters.
+ *
+ * @param sqlCaseURI the URI of sql case
+ *
+ * @return Test cases from with strategy
+ */
+ Collection<Object[]> getTestParameters(URI sqlCaseURI);
+}
diff --git a/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLocalLoader.java b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLocalLoader.java
new file mode 100644
index 00000000000..7016b9664f2
--- /dev/null
+++ b/test/integration-test/sql-parser/src/test/java/org/apache/shardingsphere/sql/parser/loader/DynamicSQLCaseLocalLoader.java
@@ -0,0 +1,48 @@
+/*
+ * 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.sql.parser.loader;
+
+import org.apache.shardingsphere.sql.parser.base.DynamicLoadingSQLParserParameterizedTest;
+import org.apache.shardingsphere.sql.parser.result.CSVResultGenerator;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.LinkedList;
+
+public class DynamicSQLCaseLocalLoader extends DynamicLoadingSQLParserParameterizedTest implements DynamicSQLCaseLoaderStrategy {
+
+ public DynamicSQLCaseLocalLoader() {
+ super("", "", "", new CSVResultGenerator(""));
+ }
+
+ /**
+ * Get test parameters.
+ *
+ * @param sqlCaseURI the URI of sql case
+ *
+ * @return Test cases from localhost.
+ **/
+ public Collection<Object[]> getTestParameters(final URI sqlCaseURI) {
+ Collection<Object[]> result = new LinkedList<>();
+ result.addAll(getSQLCases("localFile", getContent(sqlCaseURI)));
+ if (result.isEmpty()) {
+ result.add(new Object[]{"", ""});
+ }
+ return result;
+ }
+}