From c6805d21fa90ef7dd56da51606ca012a8eb32a0c Mon Sep 17 00:00:00 2001 From: shedfreewu Date: Thu, 3 Jul 2025 14:54:14 +0800 Subject: [PATCH] fix ut --- .../core/HttpServletRequestHeaderWrapper.java | 16 ++++++++++++++++ spring-cloud-tencent-dependencies/pom.xml | 2 +- .../tencent/tsf/gateway/core/model/Group.java | 16 ++++++++++++++++ .../GatewayPluginAutoConfigurationTest.java | 6 ++++++ .../ContextRoutePredicateFactoryTest.java | 9 ++++++++- .../feign/EnhancedFeignBeanPostProcessor.java | 1 + 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/HttpServletRequestHeaderWrapper.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/HttpServletRequestHeaderWrapper.java index dee164b38..fedb24e74 100644 --- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/HttpServletRequestHeaderWrapper.java +++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/HttpServletRequestHeaderWrapper.java @@ -1,3 +1,19 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.cloud.metadata.core; import java.util.Map; diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index db0fc899a..bff254c95 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -74,7 +74,7 @@ 2.0.3.0-2024.0.1-SNAPSHOT - 2.0.2.0 + 2.0.3.0-SNAPSHOT 2.2.0 diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/model/Group.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/model/Group.java index a24acc91c..05ab9bc81 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/model/Group.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/main/java/com/tencent/tsf/gateway/core/model/Group.java @@ -1,3 +1,19 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.tsf.gateway.core.model; import java.io.Serializable; diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/GatewayPluginAutoConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/GatewayPluginAutoConfigurationTest.java index 0320673bc..45c6ec6d5 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/GatewayPluginAutoConfigurationTest.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/GatewayPluginAutoConfigurationTest.java @@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAut import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.gateway.config.GatewayAutoConfiguration; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -139,5 +140,10 @@ class GatewayPluginAutoConfigurationTest { PolarisConfigProperties polarisConfigProperties() { return new PolarisConfigProperties(); } + + @Bean + LoadBalancerClientFactory loadBalancerClientFactory() { + return mock(LoadBalancerClientFactory.class); + } } } diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/context/ContextRoutePredicateFactoryTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/context/ContextRoutePredicateFactoryTest.java index 4c8e6b6ed..f60cf0198 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/context/ContextRoutePredicateFactoryTest.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-gateway-plugin/src/test/java/com/tencent/cloud/plugin/gateway/context/ContextRoutePredicateFactoryTest.java @@ -27,6 +27,7 @@ import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_PREDICATE_PATH_CONTAINER_ATTR; /** * Tests for {@link ContextRoutePredicateFactory}. @@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; class ContextRoutePredicateFactoryTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withBean(ContextGatewayPropertiesManager.class) .withBean(ContextRoutePredicateFactory.class); @Test @@ -50,7 +52,12 @@ class ContextRoutePredicateFactoryTest { GatewayPredicate gatewayPredicate = (GatewayPredicate) factory.apply(config); gatewayPredicate.toString(); - Assertions.assertTrue(gatewayPredicate.test(null)); + + MockServerWebExchange exchange = MockServerWebExchange.from( + MockServerHttpRequest.get("/test").build()); + exchange.getAttributes().put(GATEWAY_PREDICATE_PATH_CONTAINER_ATTR, "mock"); + + Assertions.assertTrue(gatewayPredicate.test(exchange)); Assertions.assertEquals(config, gatewayPredicate.getConfig()); }); } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/feign/EnhancedFeignBeanPostProcessor.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/feign/EnhancedFeignBeanPostProcessor.java index d2cd97a72..a888de25e 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/feign/EnhancedFeignBeanPostProcessor.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/feign/EnhancedFeignBeanPostProcessor.java @@ -75,6 +75,7 @@ public class EnhancedFeignBeanPostProcessor implements BeanPostProcessor, BeanFa ); } } + return createPolarisFeignClient((Client) bean); } return bean; }