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 2020/08/19 04:38:05 UTC

[shardingsphere] branch master updated: Add test case for shardingsphere-shadow-spring-boot-starter (#6922)

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 76317d8  Add test case for shardingsphere-shadow-spring-boot-starter (#6922)
76317d8 is described below

commit 76317d8c92e315e3c8ba7c9e6b61f9953ed20bd5
Author: Yanjie Zhou <zh...@aliyun.com>
AuthorDate: Wed Aug 19 12:37:42 2020 +0800

    Add test case for shardingsphere-shadow-spring-boot-starter (#6922)
---
 .../ShadowSpringBootAlgorithmProviderBeanTest.java | 54 ++++++++++++++++++++++
 .../test/resources/application-shadow.properties   | 20 ++++++++
 2 files changed, 74 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java
new file mode 100644
index 0000000..a41d68c
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.shadow.spring.boot;
+
+import org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = ShadowSpringBootAlgorithmProviderBeanTest.class)
+@SpringBootApplication
+@ActiveProfiles("shadow")
+public class ShadowSpringBootAlgorithmProviderBeanTest {
+    
+    @Resource
+    private ApplicationContext applicationContext;
+    
+    @Test
+    public void assertAlgorithmProviderBean() {
+        Object algorithmBean = applicationContext.getBean("shadow");
+        assertThat(algorithmBean.getClass(), equalTo(YamlShadowRuleConfiguration.class));
+        YamlShadowRuleConfiguration actual = YamlShadowRuleConfiguration.class.cast(algorithmBean);
+        assertThat(actual.getColumn(), is("shadow"));
+        assertThat(actual.getShadowMappings(), is(Collections.singletonMap("ds", "shadow_ds")));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties
new file mode 100644
index 0000000..6d3b4d3
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+spring.shardingsphere.rules.shadow.column=shadow
+spring.shardingsphere.rules.shadow.shadowMappings.ds=shadow_ds
+