diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/pom.xml index c0a0cf0081ef..d9447aeeb2f2 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/pom.xml +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/pom.xml @@ -38,5 +38,10 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-test + test + \ No newline at end of file diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/src/test/java/org/apache/shenyu/springboot/starter/plugin/response/ResponsePluginConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/src/test/java/org/apache/shenyu/springboot/starter/plugin/response/ResponsePluginConfigurationTest.java new file mode 100644 index 000000000000..56da497980b0 --- /dev/null +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-response/src/test/java/org/apache/shenyu/springboot/starter/plugin/response/ResponsePluginConfigurationTest.java @@ -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); + } + ); + } +}