From 133ff1b818f3400c38f4fbe7cdcf3a266357910b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=BC=E6=80=A0?= Date: Fri, 29 Jan 2021 19:31:15 +0800 Subject: [PATCH] test: Add test case for SpringCloudPluginConfiguration. (#1073) --- .../pom.xml | 15 +++++ .../SpringCloudPluginConfigurationTest.java | 65 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/src/test/java/org/dromara/soul/springboot/starter/plugin/springcloud/SpringCloudPluginConfigurationTest.java diff --git a/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/pom.xml b/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/pom.xml index f643a3b20103..a60e74f431ba 100644 --- a/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/pom.xml +++ b/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/pom.xml @@ -52,6 +52,21 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-webflux + test + + + org.assertj + assertj-core + test + \ No newline at end of file diff --git a/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/src/test/java/org/dromara/soul/springboot/starter/plugin/springcloud/SpringCloudPluginConfigurationTest.java b/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/src/test/java/org/dromara/soul/springboot/starter/plugin/springcloud/SpringCloudPluginConfigurationTest.java new file mode 100644 index 000000000000..e0709539c352 --- /dev/null +++ b/soul-spring-boot-starter/soul-spring-boot-starter-plugin/soul-spring-boot-starter-plugin-springcloud/src/test/java/org/dromara/soul/springboot/starter/plugin/springcloud/SpringCloudPluginConfigurationTest.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.dromara.soul.springboot.starter.plugin.springcloud; + +import org.dromara.soul.common.enums.PluginEnum; +import org.dromara.soul.plugin.api.SoulPlugin; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; +import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; +import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration; +import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient; +import org.springframework.web.reactive.DispatcherHandler; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * test case for {@link SpringCloudPluginConfiguration}. + * + * @author HoldDie + */ +public class SpringCloudPluginConfigurationTest { + + @Test + public void testSpringCloudPlugin() { + new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of( + RibbonAutoConfiguration.class, + DispatcherHandler.class, + RibbonClientConfiguration.class, + SpringCloudPluginConfiguration.class + )) + .withPropertyValues( + "debug=true", + "spring.main.banner-mode=off", + "ribbon.client.name=test") + .run( + context -> { + assertThat(context).hasSingleBean(LoadBalancerClient.class); + assertThat(context).hasSingleBean(RibbonAutoConfiguration.class); + assertThat(context).hasSingleBean(DispatcherHandler.class); + assertThat(context).getBean(LoadBalancerClient.class).isInstanceOf(RibbonLoadBalancerClient.class); + SoulPlugin plugin = context.getBean(SoulPlugin.class); + assertThat(plugin.named()).isEqualTo(PluginEnum.SPRING_CLOUD.getName()); + } + ); + } +}