diff --git a/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java b/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java index 0d9ac05..063ac52 100644 --- a/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java +++ b/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java @@ -103,8 +103,6 @@ public abstract class AbstractContextRefreshedEventListener namespaceIds = this.getNamespace(); namespaceIds.forEach(namespaceId -> publisher.publishEvent(buildURIRegisterDTO(context, beans, namespaceId))); diff --git a/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java b/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java index fa6aa47..7a2e1a4 100644 --- a/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java +++ b/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java @@ -93,6 +93,8 @@ private void init() { results.put("springMvcClientTestBean3", springMvcClientTestBean3); results.put("springMvcClientTestBean4", springMvcClientTestBean4); when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results); + when(applicationContext.getEnvironment()).thenReturn(env); + when(env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local"); contextRefreshedEvent = new ContextRefreshedEvent(applicationContext); ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class); Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new SpringMvcClientEventListener(shenyuClientConfig, mock(ShenyuClientRegisterRepository.class), env)); @@ -182,12 +184,12 @@ public void testOnBuildApiSuperPath() { SpringMvcClientEventListener springMvcClientEventListener = buildSpringMvcClientEventListener(false, false); Assertions.assertEquals("/order", springMvcClientEventListener.buildApiSuperPath( - SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path"); + SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path"); when(env.getProperty("spring.mvc.servlet.path")).thenReturn("/servlet-path"); when(env.getProperty("server.servlet.context-path")).thenReturn("/servlet-context-path"); Assertions.assertEquals("/servlet-context-path/servlet-path/order", springMvcClientEventListener.buildApiSuperPath( - SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path"); + SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path"); registerUtilsMockedStatic.close(); } diff --git a/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java b/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java index a81395e..e50e6a1 100644 --- a/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java +++ b/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java @@ -17,6 +17,7 @@ package org.apache.shenyu.client.tars; +import org.apache.shenyu.client.core.constant.ShenyuClientConstants; import org.apache.shenyu.client.core.enums.RpcTypeEnum; import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException; import org.apache.shenyu.client.core.register.ShenyuClientRegisterRepository; @@ -38,6 +39,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.context.ApplicationContext; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.core.env.Environment; import java.util.LinkedHashMap; import java.util.Map; @@ -68,6 +70,9 @@ public final class TarsServiceBeanPostProcessorTest { @Mock private ApplicationContext applicationContext; + @Mock + private Environment env; + private ContextRefreshedEvent contextRefreshedEvent; @BeforeEach @@ -77,6 +82,8 @@ public void init() { results.put("tarsDemoService2", tarsDemoService2); results.put("tarsDemoService3", tarsDemoService3); when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results); + when(applicationContext.getEnvironment()).thenReturn(env); + when(env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local"); contextRefreshedEvent = new ContextRefreshedEvent(applicationContext); ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class);