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/07/10 10:10:53 UTC

[shardingsphere] branch master updated: add tests (#19000)

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 7168bf117cd add tests (#19000)
7168bf117cd is described below

commit 7168bf117cd4798ed7e879742761775c1b5f2bf6
Author: Da Xiang Huang <lo...@foxmail.com>
AuthorDate: Sun Jul 10 18:10:47 2022 +0800

    add tests (#19000)
---
 .../switcher/ResourceSwitchManagerTest.java        | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java
new file mode 100644
index 00000000000..bf29b86f5c8
--- /dev/null
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.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.mode.manager.switcher;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
+import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ResourceSwitchManagerTest {
+
+    @Test
+    public void assertCreate() {
+        MockedDataSource dataSource = new MockedDataSource();
+        ShardingSphereResource resource = new ShardingSphereResource(Collections.singletonMap("foo_ds", dataSource));
+        DataSourceProperties dataSourceProperties =
+                new DataSourceProperties(MockedDataSource.class.getName(), createUserProperties("foo"));
+        ResourceSwitchManager manager = new ResourceSwitchManager();
+        SwitchingResource switchingResource = manager.create(resource, Collections.singletonMap("db", dataSourceProperties));
+        assertTrue(switchingResource.getNewDataSources().containsKey("db"));
+    }
+
+    private Map<String, Object> createUserProperties(final String username) {
+        Map<String, Object> result = new LinkedHashMap<>(1, 1);
+        result.put("username", username);
+        return result;
+    }
+}