You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/28 08:06:11 UTC
[shardingsphere] branch master updated: add unit tests for DialectDDLGeneratorFactoryTest (#17910)
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 a7d5dc61522 add unit tests for DialectDDLGeneratorFactoryTest (#17910)
a7d5dc61522 is described below
commit a7d5dc6152207564ca88f7e2376f28da94490d9f
Author: windWheel <18...@qq.com>
AuthorDate: Sat May 28 16:06:03 2022 +0800
add unit tests for DialectDDLGeneratorFactoryTest (#17910)
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
add unit tests for DialectDDLGeneratorFactoryTest
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
fix checkstyle
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
remove whitespace
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
refactor DialectDDLGeneratorFixTrue
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
export SPI
* [issue-17586](https://github.com/apache/shardingsphere/issues/17586)
fix checkstyle
* [issue-17552](https://github.com/apache/shardingsphere/issues/17552)
fix bugs
* [issue-17552](https://github.com/apache/shardingsphere/issues/17555)
remove fields
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
remove fields
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
add license and remove whitespace
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
add license
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
fix ci
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
fix ci
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
fix ci
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
repair review comment
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
repair review comment
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
repair review comment
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
fix checkstyle
* [issue-17555](https://github.com/apache/shardingsphere/issues/17555)
add maven scope
---
.../shardingsphere-data-pipeline-api/pom.xml | 6 ++
.../DialectDDLGeneratorFactoryTest.java | 39 +++++++++++++
.../pipeline/spi/fixture/DatabaseTypeFixture.java | 65 ++++++++++++++++++++++
.../spi/fixture/DialectDDLGeneratorFixture.java | 37 ++++++++++++
...a.pipeline.spi.ddlgenerator.DialectDDLGenerator | 18 ++++++
...shardingsphere.infra.database.type.DatabaseType | 18 ++++++
6 files changed, 183 insertions(+)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/pom.xml b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/pom.xml
index 3dc7116af71..d6bd90ec6a8 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/pom.xml
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/pom.xml
@@ -33,6 +33,12 @@
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-common</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ddlgenerator/DialectDDLGeneratorFactoryTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ddlgenerator/DialectDDLGeneratorFactoryTest.java
new file mode 100644
index 00000000000..30ed017061e
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ddlgenerator/DialectDDLGeneratorFactoryTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.data.pipeline.spi.ddlgenerator;
+
+import java.sql.SQLException;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+public final class DialectDDLGeneratorFactoryTest {
+
+ @Test
+ public void assertFindInstanceWithDialectDDLGenerator() throws SQLException {
+ String databaseType = "FIXTURE";
+ DatabaseType type = DatabaseTypeFactory.getInstance(databaseType);
+ assertTrue(DialectDDLSQLGeneratorFactory.findInstance(type).isPresent());
+ DialectDDLGenerator dialectDDLGenerator = DialectDDLSQLGeneratorFactory.findInstance(type).get();
+ assertThat(dialectDDLGenerator.generateDDLSQL("tableA", "", new MockedDataSource()), is("SHOW CREATE TABLE tableA"));
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DatabaseTypeFixture.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DatabaseTypeFixture.java
new file mode 100644
index 00000000000..b37eae06a94
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DatabaseTypeFixture.java
@@ -0,0 +1,65 @@
+/*
+ * 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.data.pipeline.spi.fixture;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+import static org.mockito.Mockito.mock;
+
+public final class DatabaseTypeFixture implements DatabaseType {
+
+ @Override
+ public String getType() {
+ return "FIXTURE";
+ }
+
+ @Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.NONE;
+ }
+
+ @Override
+ public Collection<String> getJdbcUrlPrefixes() {
+ return Collections.singleton("jdbc:fixture");
+ }
+
+ @Override
+ public DataSourceMetaData getDataSourceMetaData(final String url, final String username) {
+ return mock(DataSourceMetaData.class);
+ }
+
+ @Override
+ public Optional<String> getDataSourceClassName() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Map<String, Collection<String>> getSystemDatabaseSchemaMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Collection<String> getSystemSchemas() {
+ return Collections.emptyList();
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DialectDDLGeneratorFixture.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DialectDDLGeneratorFixture.java
new file mode 100644
index 00000000000..acc1607e22f
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/java/org/apache/shardingsphere/data/pipeline/spi/fixture/DialectDDLGeneratorFixture.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.data.pipeline.spi.fixture;
+
+import java.sql.SQLException;
+import javax.sql.DataSource;
+import org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.DialectDDLGenerator;
+
+public final class DialectDDLGeneratorFixture implements DialectDDLGenerator {
+
+ private static final String SHOW_CREATE_SQL = "SHOW CREATE TABLE %s";
+
+ @Override
+ public String generateDDLSQL(final String tableName, final String schemaName, final DataSource dataSource) throws SQLException {
+ return String.format(SHOW_CREATE_SQL, tableName);
+ }
+
+ @Override
+ public String getType() {
+ return "FIXTURE";
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.DialectDDLGenerator b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.DialectDDLGenerator
new file mode 100644
index 00000000000..c1d897de1ed
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.DialectDDLGenerator
@@ -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.data.pipeline.spi.fixture.DialectDDLGeneratorFixture
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
new file mode 100644
index 00000000000..87ea61e5839
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
@@ -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.data.pipeline.spi.fixture.DatabaseTypeFixture