Skip to content

Commit

Permalink
test: Add test case for SpringCloudPluginConfiguration. (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asxing authored Jan 29, 2021
1 parent ce242e0 commit 133ff1b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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());
}
);
}
}

0 comments on commit 133ff1b

Please sign in to comment.