Skip to content

Commit

Permalink
add test case for shenyu-spring-boot-starter-plugin-response module (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
renzhuyan committed Jun 20, 2021
1 parent d87ebaa commit cb45266
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Expand Up @@ -38,5 +38,10 @@
<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>
</dependencies>
</project>
@@ -0,0 +1,85 @@
/*
* 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.shenyu.springboot.starter.plugin.response;

import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.plugin.api.ShenyuPlugin;
import org.apache.shenyu.plugin.response.ResponsePlugin;
import org.apache.shenyu.plugin.response.strategy.MessageWriter;
import org.apache.shenyu.plugin.response.strategy.NettyClientMessageWriter;
import org.apache.shenyu.plugin.response.strategy.WebClientMessageWriter;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Test case for {@link ResponsePluginConfiguration}.
**/
public class ResponsePluginConfigurationTest {

@Test
public void testResponsePlugin() {
new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(ResponsePluginConfiguration.class)
)
.withPropertyValues("debug=true")
.run(
context -> {
assertThat(context).hasSingleBean(MessageWriter.class);
assertThat(context).hasSingleBean(ShenyuPlugin.class);
ShenyuPlugin plugin = context.getBean("responsePlugin", ShenyuPlugin.class);
assertThat(plugin instanceof ResponsePlugin).isEqualTo(true);
assertThat(plugin.named()).isEqualTo(PluginEnum.RESPONSE.getName());

}
);
}

@Test
public void testWebClientMessageWriter() {
new ApplicationContextRunner().withPropertyValues("shenyu.httpclient.strategy=webClient")
.withConfiguration(
AutoConfigurations.of(ResponsePluginConfiguration.class)
)
.withPropertyValues("debug=true")
.run(
context -> {
MessageWriter messageWriter = context.getBean("webClientMessageWriter", MessageWriter.class);
assertThat(messageWriter instanceof WebClientMessageWriter).isEqualTo(true);
}
);
}

@Test
public void testNettyClientMessageWriter() {
new ApplicationContextRunner().withPropertyValues("shenyu.httpclient.strategy=netty")
.withConfiguration(
AutoConfigurations.of(ResponsePluginConfiguration.class)
)
.withPropertyValues("debug=true")
.run(
context -> {
MessageWriter messageWriter = context.getBean("nettyMessageWriter", MessageWriter.class);
assertThat(messageWriter instanceof NettyClientMessageWriter).isEqualTo(true);
}
);
}
}

0 comments on commit cb45266

Please sign in to comment.