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/06/21 04:41:42 UTC

[shardingsphere] branch master updated: Add test for OptimizerSqlDialectBuilderFactory (#17928)

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 4c8c7c5e1c2 Add test for OptimizerSqlDialectBuilderFactory (#17928)
4c8c7c5e1c2 is described below

commit 4c8c7c5e1c242f1c9906afcedc899f43f5784466
Author: windWheel <18...@qq.com>
AuthorDate: Tue Jun 21 12:41:28 2022 +0800

    Add test for OptimizerSqlDialectBuilderFactory (#17928)
    
    * Add test for OptimizerSqlDialectBuilderFactory
---
 .../OptimizerSQLDialectBuilderFactoryTest.java     | 38 +++++++++++++
 .../parser/fixture/FixtureDatabaseType.java        | 62 ++++++++++++++++++++++
 .../fixture/OptimizerSQLDialectBuilderFixture.java | 36 +++++++++++++
 ...shardingsphere.infra.database.type.DatabaseType | 18 +++++++
 ...ntext.parser.dialect.OptimizerSQLDialectBuilder | 18 +++++++
 5 files changed, 172 insertions(+)

diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/dialect/OptimizerSQLDialectBuilderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/dialect/OptimizerSQLDialectBuilderFactoryTest.java
new file mode 100644
index 00000000000..d9b07ae81db
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/dialect/OptimizerSQLDialectBuilderFactoryTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.federation.optimizer.context.parser.dialect;
+
+import java.util.Properties;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.federation.optimizer.context.parser.fixture.OptimizerSQLDialectBuilderFixture;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
+public final class OptimizerSQLDialectBuilderFactoryTest {
+    
+    @Test
+    public void assertCreateOptimizerSQLDialectBuilder() {
+        DatabaseType type = DatabaseTypeFactory.getInstance("FIXTURE");
+        Properties actual = OptimizerSQLDialectBuilderFactory.build(type);
+        OptimizerSQLDialectBuilder builder = new OptimizerSQLDialectBuilderFixture();
+        Properties excepted = builder.build();
+        assertThat(actual, equalTo(excepted));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/FixtureDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/FixtureDatabaseType.java
new file mode 100644
index 00000000000..b0155b90e4a
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/FixtureDatabaseType.java
@@ -0,0 +1,62 @@
+/*
+ * 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.federation.optimizer.context.parser.fixture;
+
+import java.util.Collection;
+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;
+
+public class FixtureDatabaseType implements DatabaseType {
+    @Override
+    public QuoteCharacter getQuoteCharacter() {
+        return null;
+    }
+
+    @Override
+    public Collection<String> getJdbcUrlPrefixes() {
+        return null;
+    }
+
+    @Override
+    public DataSourceMetaData getDataSourceMetaData(final String url, final String username) {
+        return null;
+    }
+
+    @Override
+    public Optional<String> getDataSourceClassName() {
+        return Optional.empty();
+    }
+
+    @Override
+    public Map<String, Collection<String>> getSystemDatabaseSchemaMap() {
+        return null;
+    }
+
+    @Override
+    public Collection<String> getSystemSchemas() {
+        return null;
+    }
+
+    @Override
+    public String getType() {
+        return "FIXTURE";
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/OptimizerSQLDialectBuilderFixture.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/OptimizerSQLDialectBuilderFixture.java
new file mode 100644
index 00000000000..7de11d11532
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/fixture/OptimizerSQLDialectBuilderFixture.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.federation.optimizer.context.parser.fixture;
+
+import java.util.Properties;
+import org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilder;
+
+public final class OptimizerSQLDialectBuilderFixture implements OptimizerSQLDialectBuilder {
+    
+    @Override
+    public Properties build() {
+        Properties properties = new Properties();
+        properties.setProperty("fixture", "fixture");
+        return properties;
+    }
+    
+    @Override
+    public String getType() {
+        return "FIXTURE";
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.type.DatabaseType
new file mode 100644
index 00000000000..36adc826199
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/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.infra.federation.optimizer.context.parser.fixture.FixtureDatabaseType
diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilder b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilder
new file mode 100644
index 00000000000..31af89156d4
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilder
@@ -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.federation.optimizer.context.parser.fixture.OptimizerSQLDialectBuilderFixture