This is an automated email from the ASF dual-hosted git repository.
panjuan 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 861bda1 Add unit test for TableMetaDataUtil (#12907)
861bda1 is described below
commit 861bda12ea1d69db58951b19e9365a2ce8f17264
Author: Zhu jun <[email protected]>
AuthorDate: Wed Oct 6 18:29:25 2021 +0800
Add unit test for TableMetaDataUtil (#12907)
* Add unit test for TableMetaDataUtil
* code style fix
* code style fix
---
.../schema/builder/util/IndexMetaDataUtilTest.java | 2 +-
.../schema/builder/util/TableMetaDataUtilTest.java | 81 ++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/IndexMetaDataUtilTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/IndexMetaDataUtilTest.java
index 0c61cf7..cb71070 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/IndexMetaDataUtilTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/IndexMetaDataUtilTest.java
@@ -22,7 +22,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public class IndexMetaDataUtilTest {
+public final class IndexMetaDataUtilTest {
@Test
public void assertGetLogicIndexNameWithIndexNameSuffix() {
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/TableMetaDataUtilTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/TableMetaDataUtilTest.java
new file mode 100644
index 0000000..511e1d8
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/util/TableMetaDataUtilTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.metadata.schema.builder.util;
+
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
+import
org.apache.shardingsphere.infra.metadata.schema.builder.loader.TableMetaDataLoaderMaterial;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.sql.DataSource;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+import static org.hamcrest.CoreMatchers.is;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class TableMetaDataUtilTest {
+
+ @Mock
+ private SchemaBuilderMaterials materials;
+
+ @Mock
+ private DataSourceContainedRule dataSourceContainedRule;
+
+ @Mock
+ private DataNodeContainedRule dataNodeContainedRule;
+
+ @Mock
+ private DataSource dataSource1;
+
+ @Mock
+ private DataSource dataSource2;
+
+ @Test
+ public void assertGetTableMetaDataLoadMaterial() {
+ Map<String, Collection<DataNode>> dataNodes = new HashMap<>();
+ dataNodes.put("t_user", Arrays.asList(new DataNode("ds0.t_user")));
+ dataNodes.put("t_order", Arrays.asList(new DataNode("ds1.t_order")));
+ when(dataNodeContainedRule.getAllDataNodes()).thenReturn(dataNodes);
+ Map<String, Collection<String>> dataSourceMapper = new HashMap<>();
+
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(dataSourceMapper);
+ Collection<ShardingSphereRule> rules = new LinkedList<>();
+ rules.add(dataNodeContainedRule);
+ rules.add(dataSourceContainedRule);
+ when(materials.getRules()).thenReturn(rules);
+ Map<String, DataSource> dataSourceMap = new HashMap<>();
+ dataSourceMap.put("ds0", dataSource1);
+ dataSourceMap.put("ds1", dataSource2);
+ when(materials.getDataSourceMap()).thenReturn(dataSourceMap);
+ Collection<String> tableNames = new LinkedList<>();
+ tableNames.add("t_user");
+ Collection<TableMetaDataLoaderMaterial> results =
TableMetaDataUtil.getTableMetaDataLoadMaterial(tableNames, materials, false);
+ assertThat(results.size(), is(1));
+ }
+}